tinybase 4.3.23 → 4.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/debug/store.js +112 -25
- package/lib/debug/tinybase.js +112 -25
- package/lib/debug/ui-react-dom.js +112 -25
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/ui-react-dom-debug.js +1 -1
- package/lib/es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/types/store.d.ts +911 -31
- package/lib/types/with-schemas/store.d.ts +1179 -35
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react-dom-debug.js +1 -1
- package/lib/umd/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom-debug.js +1 -1
- package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
- package/package.json +4 -4
- package/readme.md +13 -13
package/lib/types/store.d.ts
CHANGED
|
@@ -529,9 +529,26 @@ export type TransactionListener = (
|
|
|
529
529
|
getTransactionLog: GetTransactionLog,
|
|
530
530
|
) => void;
|
|
531
531
|
|
|
532
|
+
/**
|
|
533
|
+
* The HasTablesListener type describes a function that is used to listen to
|
|
534
|
+
* Tables as a whole being added to or removed from the Store.
|
|
535
|
+
*
|
|
536
|
+
* A HasTablesListener is provided when using the addHasTablesListener method.
|
|
537
|
+
* See that method for specific examples.
|
|
538
|
+
*
|
|
539
|
+
* When called, a HasTablesListener is given a reference to the Store. It is
|
|
540
|
+
* also given a flag to indicate whether Tables now exist (having not done
|
|
541
|
+
* previously), or do not (having done so previously).
|
|
542
|
+
* @param store A reference to the Store that changed.
|
|
543
|
+
* @param hasTables Whether Tables now exist or not.
|
|
544
|
+
* @category Listener
|
|
545
|
+
* @since v4.4.0
|
|
546
|
+
*/
|
|
547
|
+
export type HasTablesListener = (store: Store, hasTables: boolean) => void;
|
|
548
|
+
|
|
532
549
|
/**
|
|
533
550
|
* The TablesListener type describes a function that is used to listen to
|
|
534
|
-
* changes to the
|
|
551
|
+
* changes to the tabular part of the Store.
|
|
535
552
|
*
|
|
536
553
|
* A TablesListener is provided when using the addTablesListener method. See
|
|
537
554
|
* that method for specific examples.
|
|
@@ -574,6 +591,29 @@ export type TableIdsListener = (
|
|
|
574
591
|
getIdChanges: GetIdChanges | undefined,
|
|
575
592
|
) => void;
|
|
576
593
|
|
|
594
|
+
/**
|
|
595
|
+
* The HasTableListener type describes a function that is used to listen to a
|
|
596
|
+
* Table being added to or removed from the Store.
|
|
597
|
+
*
|
|
598
|
+
* A HasTableListener is provided when using the addHasTableListener method. See
|
|
599
|
+
* that method for specific examples.
|
|
600
|
+
*
|
|
601
|
+
* When called, a HasTableListener is given a reference to the Store, and the Id
|
|
602
|
+
* of the Table that changed. It is also given a flag to indicate whether the
|
|
603
|
+
* Table now exists (having not done previously), or does not (having done so
|
|
604
|
+
* previously).
|
|
605
|
+
* @param store A reference to the Store that changed.
|
|
606
|
+
* @param tableId The Id of the Table that changed.
|
|
607
|
+
* @param hasTable Whether the Table now exists or not.
|
|
608
|
+
* @category Listener
|
|
609
|
+
* @since v4.4.0
|
|
610
|
+
*/
|
|
611
|
+
export type HasTableListener = (
|
|
612
|
+
store: Store,
|
|
613
|
+
tableId: Id,
|
|
614
|
+
hasTable: boolean,
|
|
615
|
+
) => void;
|
|
616
|
+
|
|
577
617
|
/**
|
|
578
618
|
* The TableListener type describes a function that is used to listen to changes
|
|
579
619
|
* to a Table.
|
|
@@ -622,6 +662,31 @@ export type TableCellIdsListener = (
|
|
|
622
662
|
getIdChanges: GetIdChanges | undefined,
|
|
623
663
|
) => void;
|
|
624
664
|
|
|
665
|
+
/**
|
|
666
|
+
* The HasTableCellListener type describes a function that is used to listen to
|
|
667
|
+
* a Cell being added to or removed from a Table as a whole.
|
|
668
|
+
*
|
|
669
|
+
* A HasTableCellListener is provided when using the addHasTableCellListener
|
|
670
|
+
* method. See that method for specific examples.
|
|
671
|
+
*
|
|
672
|
+
* When called, a HasTableCellListener is given a reference to the Store, the Id
|
|
673
|
+
* of the Table that changed, and the Id of the Cell that changed. It is also
|
|
674
|
+
* given a flag to indicate whether the Cell now exists anywhere in the Table
|
|
675
|
+
* (having not done previously), or does not (having done so previously).
|
|
676
|
+
* @param store A reference to the Store that changed.
|
|
677
|
+
* @param tableId The Id of the Table that changed.
|
|
678
|
+
* @param cellId The Id of the Table Cell that changed.
|
|
679
|
+
* @param hasTableCell Whether the Cell now exists anywhere in the Table or not.
|
|
680
|
+
* @category Listener
|
|
681
|
+
* @since v4.4.0
|
|
682
|
+
*/
|
|
683
|
+
export type HasTableCellListener = (
|
|
684
|
+
store: Store,
|
|
685
|
+
tableId: Id,
|
|
686
|
+
cellId: Id,
|
|
687
|
+
hasTableCell: boolean,
|
|
688
|
+
) => void;
|
|
689
|
+
|
|
625
690
|
/**
|
|
626
691
|
* The RowCountListener type describes a function that is used to listen to
|
|
627
692
|
* changes to the number of Row objects in a Table.
|
|
@@ -700,6 +765,31 @@ export type SortedRowIdsListener = (
|
|
|
700
765
|
sortedRowIds: Ids,
|
|
701
766
|
) => void;
|
|
702
767
|
|
|
768
|
+
/**
|
|
769
|
+
* The HasRowListener type describes a function that is used to listen to a Row
|
|
770
|
+
* being added to or removed from the Store.
|
|
771
|
+
*
|
|
772
|
+
* A HasRowListener is provided when using the addHasRowListener method. See
|
|
773
|
+
* that method for specific examples.
|
|
774
|
+
*
|
|
775
|
+
* When called, a HasRowListener is given a reference to the Store, the Id of
|
|
776
|
+
* the Table that changed, and the Id of the Row that changed. It is also given
|
|
777
|
+
* a flag to indicate whether the Row now exists (having not done previously),
|
|
778
|
+
* or does not (having done so previously).
|
|
779
|
+
* @param store A reference to the Store that changed.
|
|
780
|
+
* @param tableId The Id of the Table that changed.
|
|
781
|
+
* @param rowId The Id of the Row that changed.
|
|
782
|
+
* @param hasRow Whether the Row now exists or not.
|
|
783
|
+
* @category Listener
|
|
784
|
+
* @since v4.4.0
|
|
785
|
+
*/
|
|
786
|
+
export type HasRowListener = (
|
|
787
|
+
store: Store,
|
|
788
|
+
tableId: Id,
|
|
789
|
+
rowId: Id,
|
|
790
|
+
hasRow: boolean,
|
|
791
|
+
) => void;
|
|
792
|
+
|
|
703
793
|
/**
|
|
704
794
|
* The RowListener type describes a function that is used to listen to changes
|
|
705
795
|
* to a Row.
|
|
@@ -755,6 +845,33 @@ export type CellIdsListener = (
|
|
|
755
845
|
getIdChanges: GetIdChanges | undefined,
|
|
756
846
|
) => void;
|
|
757
847
|
|
|
848
|
+
/**
|
|
849
|
+
* The HasCellListener type describes a function that is used to listen to a
|
|
850
|
+
* Cell being added to or removed from the Store.
|
|
851
|
+
*
|
|
852
|
+
* A HasCellListener is provided when using the addHasCellListener method. See
|
|
853
|
+
* that method for specific examples.
|
|
854
|
+
*
|
|
855
|
+
* When called, a HasCellListener is given a reference to the Store, the Id of
|
|
856
|
+
* the Table that changed, the Id of the Row that changed, and the Id of Cell
|
|
857
|
+
* that changed. It is also given a flag to indicate whether the Cell now exists
|
|
858
|
+
* (having not done previously), or does not (having done so previously).
|
|
859
|
+
* @param store A reference to the Store that changed.
|
|
860
|
+
* @param tableId The Id of the Table that changed.
|
|
861
|
+
* @param rowId The Id of the Row that changed.
|
|
862
|
+
* @param cellId The Id of the Cell that changed.
|
|
863
|
+
* @param hasCell Whether the Cell now exists or not.
|
|
864
|
+
* @category Listener
|
|
865
|
+
* @since v4.4.0
|
|
866
|
+
*/
|
|
867
|
+
export type HasCellListener = (
|
|
868
|
+
store: Store,
|
|
869
|
+
tableId: Id,
|
|
870
|
+
rowId: Id,
|
|
871
|
+
cellId: Id,
|
|
872
|
+
hasCell: boolean,
|
|
873
|
+
) => void;
|
|
874
|
+
|
|
758
875
|
/**
|
|
759
876
|
* The CellListener type describes a function that is used to listen to changes
|
|
760
877
|
* to a Cell.
|
|
@@ -792,6 +909,23 @@ export type CellListener = (
|
|
|
792
909
|
getCellChange: GetCellChange | undefined,
|
|
793
910
|
) => void;
|
|
794
911
|
|
|
912
|
+
/**
|
|
913
|
+
* The HasValuesListener type describes a function that is used to listen to
|
|
914
|
+
* Values as a whole being added to or removed from the Store.
|
|
915
|
+
*
|
|
916
|
+
* A HasValuesListener is provided when using the addHasValuesListener method.
|
|
917
|
+
* See that method for specific examples.
|
|
918
|
+
*
|
|
919
|
+
* When called, a HasValuesListener is given a reference to the Store. It is
|
|
920
|
+
* also given a flag to indicate whether Values now exist (having not done
|
|
921
|
+
* previously), or do not (having done so previously).
|
|
922
|
+
* @param store A reference to the Store that changed.
|
|
923
|
+
* @param hasValues Whether Values now exist or not.
|
|
924
|
+
* @category Listener
|
|
925
|
+
* @since v4.4.0
|
|
926
|
+
*/
|
|
927
|
+
export type HasValuesListener = (store: Store, hasValues: boolean) => void;
|
|
928
|
+
|
|
795
929
|
/**
|
|
796
930
|
* The ValuesListener type describes a function that is used to listen to
|
|
797
931
|
* changes to all the Values in a Store.
|
|
@@ -837,6 +971,29 @@ export type ValueIdsListener = (
|
|
|
837
971
|
getIdChanges: GetIdChanges | undefined,
|
|
838
972
|
) => void;
|
|
839
973
|
|
|
974
|
+
/**
|
|
975
|
+
* The HasValueListener type describes a function that is used to listen to a
|
|
976
|
+
* Value being added to or removed from the Store.
|
|
977
|
+
*
|
|
978
|
+
* A HasValueListener is provided when using the addHasValueListener method. See
|
|
979
|
+
* that method for specific examples.
|
|
980
|
+
*
|
|
981
|
+
* When called, a HasValueListener is given a reference to the Store and the Id
|
|
982
|
+
* of Value that changed. It is also given a flag to indicate whether the Value
|
|
983
|
+
* now exists (having not done previously), or does not (having done so
|
|
984
|
+
* previously).
|
|
985
|
+
* @param store A reference to the Store that changed.
|
|
986
|
+
* @param valueId The Id of the Value that changed.
|
|
987
|
+
* @param hasValue Whether the Value now exists or not.
|
|
988
|
+
* @category Listener
|
|
989
|
+
* @since v4.4.0
|
|
990
|
+
*/
|
|
991
|
+
export type HasValueListener = (
|
|
992
|
+
store: Store,
|
|
993
|
+
valueId: Id,
|
|
994
|
+
hasValue: boolean,
|
|
995
|
+
) => void;
|
|
996
|
+
|
|
840
997
|
/**
|
|
841
998
|
* The ValueListener type describes a function that is used to listen to changes
|
|
842
999
|
* to a Value.
|
|
@@ -1257,6 +1414,11 @@ export type GetTransactionLog = () => TransactionLog;
|
|
|
1257
1414
|
* @category Development
|
|
1258
1415
|
*/
|
|
1259
1416
|
export type StoreListenerStats = {
|
|
1417
|
+
/**
|
|
1418
|
+
* The number of HasTablesListener functions registered with the Store, since
|
|
1419
|
+
* v4.4.
|
|
1420
|
+
*/
|
|
1421
|
+
hasTables?: number;
|
|
1260
1422
|
/**
|
|
1261
1423
|
* The number of TablesListener functions registered with the Store.
|
|
1262
1424
|
*/
|
|
@@ -1265,6 +1427,11 @@ export type StoreListenerStats = {
|
|
|
1265
1427
|
* The number of TableIdsListener functions registered with the Store.
|
|
1266
1428
|
*/
|
|
1267
1429
|
tableIds?: number;
|
|
1430
|
+
/**
|
|
1431
|
+
* The number of HasTableListener functions registered with the Store, since
|
|
1432
|
+
* v4.4.
|
|
1433
|
+
*/
|
|
1434
|
+
hasTable?: number;
|
|
1268
1435
|
/**
|
|
1269
1436
|
* The number of TableListener functions registered with the Store.
|
|
1270
1437
|
*/
|
|
@@ -1274,6 +1441,11 @@ export type StoreListenerStats = {
|
|
|
1274
1441
|
* since v3.3.
|
|
1275
1442
|
*/
|
|
1276
1443
|
tableCellIds?: number;
|
|
1444
|
+
/**
|
|
1445
|
+
* The number of HasTableCellListener functions registered with the Store,
|
|
1446
|
+
* since v4.4.
|
|
1447
|
+
*/
|
|
1448
|
+
hasTableCell?: number;
|
|
1277
1449
|
/**
|
|
1278
1450
|
* The number of RowCountListener functions registered with the Store, since
|
|
1279
1451
|
* v4.1.0
|
|
@@ -1287,6 +1459,11 @@ export type StoreListenerStats = {
|
|
|
1287
1459
|
* The number of SortedRowIdsListener functions registered with the Store.
|
|
1288
1460
|
*/
|
|
1289
1461
|
sortedRowIds?: number;
|
|
1462
|
+
/**
|
|
1463
|
+
* The number of HasRowListener functions registered with the Store, since
|
|
1464
|
+
* v4.4.
|
|
1465
|
+
*/
|
|
1466
|
+
hasRow?: number;
|
|
1290
1467
|
/**
|
|
1291
1468
|
* The number of RowListener functions registered with the Store.
|
|
1292
1469
|
*/
|
|
@@ -1295,6 +1472,11 @@ export type StoreListenerStats = {
|
|
|
1295
1472
|
* The number of CellIdsListener functions registered with the Store.
|
|
1296
1473
|
*/
|
|
1297
1474
|
cellIds?: number;
|
|
1475
|
+
/**
|
|
1476
|
+
* The number of HasCellListener functions registered with the Store, since
|
|
1477
|
+
* v4.4.
|
|
1478
|
+
*/
|
|
1479
|
+
hasCell?: number;
|
|
1298
1480
|
/**
|
|
1299
1481
|
* The number of CellListener functions registered with the Store.
|
|
1300
1482
|
*/
|
|
@@ -1303,6 +1485,11 @@ export type StoreListenerStats = {
|
|
|
1303
1485
|
* The number of InvalidCellListener functions registered with the Store.
|
|
1304
1486
|
*/
|
|
1305
1487
|
invalidCell?: number;
|
|
1488
|
+
/**
|
|
1489
|
+
* The number of HasValuesListener functions registered with the Store, since
|
|
1490
|
+
* v4.4.
|
|
1491
|
+
*/
|
|
1492
|
+
hasValues?: number;
|
|
1306
1493
|
/**
|
|
1307
1494
|
* The number of ValuesListener functions registered with the Store, since
|
|
1308
1495
|
* v3.0.
|
|
@@ -1313,6 +1500,11 @@ export type StoreListenerStats = {
|
|
|
1313
1500
|
* v3.0.
|
|
1314
1501
|
*/
|
|
1315
1502
|
valueIds?: number;
|
|
1503
|
+
/**
|
|
1504
|
+
* The number of HasValueListener functions registered with the Store, since
|
|
1505
|
+
* v4.4.
|
|
1506
|
+
*/
|
|
1507
|
+
hasValue?: number;
|
|
1316
1508
|
/**
|
|
1317
1509
|
* The number of ValueListener functions registered with the Store, since
|
|
1318
1510
|
* v3.0.
|
|
@@ -1478,6 +1670,10 @@ export type StoreListenerStats = {
|
|
|
1478
1670
|
* |Row|hasRow|forEachRow|
|
|
1479
1671
|
* |Cell|hasCell|forEachCell|
|
|
1480
1672
|
*
|
|
1673
|
+
* Since v4.3.23, you can add listeners for the change of existence of part of a
|
|
1674
|
+
* Store. For example, the addHasValueListener method lets you listen for a
|
|
1675
|
+
* Value being added or removed.
|
|
1676
|
+
*
|
|
1481
1677
|
* Finally, the getListenerStats method describes the current state of the
|
|
1482
1678
|
* Store's listeners for debugging purposes.
|
|
1483
1679
|
* @example
|
|
@@ -3920,6 +4116,71 @@ export interface Store {
|
|
|
3920
4116
|
*/
|
|
3921
4117
|
forEachValue(valueCallback: ValueCallback): void;
|
|
3922
4118
|
|
|
4119
|
+
/**
|
|
4120
|
+
* The addHasTablesListener method registers a listener function with the
|
|
4121
|
+
* Store that will be called when Tables as a whole are added to or removed
|
|
4122
|
+
* from the Store.
|
|
4123
|
+
*
|
|
4124
|
+
* The provided listener is a HasTablesListener function, and will be called
|
|
4125
|
+
* with a reference to the Store. It is also given a flag to indicate whether
|
|
4126
|
+
* Tables now exist (having not done previously), or do not (having done so
|
|
4127
|
+
* previously).
|
|
4128
|
+
*
|
|
4129
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4130
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4131
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4132
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4133
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4134
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4135
|
+
* though they will fire non-mutator listeners.
|
|
4136
|
+
* @param listener The function that will be called whenever Tables as a whole
|
|
4137
|
+
* are added or removed.
|
|
4138
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4139
|
+
* Store data.
|
|
4140
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4141
|
+
* explicitly, or to remove it.
|
|
4142
|
+
* @example
|
|
4143
|
+
* This example registers a listener that responds to Tables being added or
|
|
4144
|
+
* removed.
|
|
4145
|
+
*
|
|
4146
|
+
* ```js
|
|
4147
|
+
* const store = createStore().setTables({
|
|
4148
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4149
|
+
* });
|
|
4150
|
+
* const listenerId = store.addHasTablesListener((store, hasTables) => {
|
|
4151
|
+
* console.log('Tables ' + (hasTables ? 'added' : 'removed'));
|
|
4152
|
+
* });
|
|
4153
|
+
*
|
|
4154
|
+
* store.delTables();
|
|
4155
|
+
* // -> 'Tables removed'
|
|
4156
|
+
*
|
|
4157
|
+
* store.setTables({species: {dog: {price: 5}}});
|
|
4158
|
+
* // -> 'Tables added'
|
|
4159
|
+
*
|
|
4160
|
+
* store.delListener(listenerId);
|
|
4161
|
+
* ```
|
|
4162
|
+
* @example
|
|
4163
|
+
* This example registers a listener that responds to Tables being added or
|
|
4164
|
+
* removed, and which also mutates the Store itself.
|
|
4165
|
+
*
|
|
4166
|
+
* ```js
|
|
4167
|
+
* const store = createStore();
|
|
4168
|
+
* const listenerId = store.addHasTablesListener(
|
|
4169
|
+
* (store, hasTables) => store.setValue('hasTables', hasTables),
|
|
4170
|
+
* true,
|
|
4171
|
+
* );
|
|
4172
|
+
*
|
|
4173
|
+
* store.setTables({species: {dog: {price: 5}}});
|
|
4174
|
+
* console.log(store.getValues());
|
|
4175
|
+
* // -> {hasTables: true}
|
|
4176
|
+
*
|
|
4177
|
+
* store.delListener(listenerId);
|
|
4178
|
+
* ```
|
|
4179
|
+
* @category Listener
|
|
4180
|
+
* @since v4.4.0
|
|
4181
|
+
*/
|
|
4182
|
+
addHasTablesListener(listener: HasTablesListener, mutator?: boolean): Id;
|
|
4183
|
+
|
|
3923
4184
|
/**
|
|
3924
4185
|
* The addTablesListener method registers a listener function with the Store
|
|
3925
4186
|
* that will be called whenever data in the Store changes.
|
|
@@ -4045,6 +4306,107 @@ export interface Store {
|
|
|
4045
4306
|
*/
|
|
4046
4307
|
addTableIdsListener(listener: TableIdsListener, mutator?: boolean): Id;
|
|
4047
4308
|
|
|
4309
|
+
/**
|
|
4310
|
+
* The addHasTableListener method registers a listener function with the Store
|
|
4311
|
+
* that will be called when a Table is added to or removed from the Store.
|
|
4312
|
+
*
|
|
4313
|
+
* The provided listener is a HasTableListener function, and will be called
|
|
4314
|
+
* with a reference to the Store and the Id of the Table that changed. It is
|
|
4315
|
+
* also given a flag to indicate whether the Table now exists (having not done
|
|
4316
|
+
* previously), or does not (having done so previously).
|
|
4317
|
+
*
|
|
4318
|
+
* You can either listen to a single Table being added or removed (by
|
|
4319
|
+
* specifying the Table Id as the method's first parameter) or changes to any
|
|
4320
|
+
* Table (by providing a `null` wildcard).
|
|
4321
|
+
*
|
|
4322
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4323
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4324
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4325
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4326
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4327
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4328
|
+
* though they will fire non-mutator listeners.
|
|
4329
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
4330
|
+
* @param listener The function that will be called whenever the matching
|
|
4331
|
+
* Table is added or removed.
|
|
4332
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4333
|
+
* Store data.
|
|
4334
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4335
|
+
* explicitly, or to remove it.
|
|
4336
|
+
* @example
|
|
4337
|
+
* This example registers a listener that responds to a specific Table being
|
|
4338
|
+
* added or removed.
|
|
4339
|
+
*
|
|
4340
|
+
* ```js
|
|
4341
|
+
* const store = createStore().setTables({
|
|
4342
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4343
|
+
* });
|
|
4344
|
+
* const listenerId = store.addHasTableListener(
|
|
4345
|
+
* 'pets',
|
|
4346
|
+
* (store, tableId, hasTable) => {
|
|
4347
|
+
* console.log('pets table ' + (hasTable ? 'added' : 'removed'));
|
|
4348
|
+
* },
|
|
4349
|
+
* );
|
|
4350
|
+
*
|
|
4351
|
+
* store.delTable('pets');
|
|
4352
|
+
* // -> 'pets table removed'
|
|
4353
|
+
*
|
|
4354
|
+
* store.setTable('pets', {fido: {species: 'dog', color: 'brown'}});
|
|
4355
|
+
* // -> 'pets table added'
|
|
4356
|
+
*
|
|
4357
|
+
* store.delListener(listenerId);
|
|
4358
|
+
* ```
|
|
4359
|
+
* @example
|
|
4360
|
+
* This example registers a listener that responds to any Table being added or
|
|
4361
|
+
* removed.
|
|
4362
|
+
*
|
|
4363
|
+
* ```js
|
|
4364
|
+
* const store = createStore().setTables({
|
|
4365
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4366
|
+
* });
|
|
4367
|
+
* const listenerId = store.addHasTableListener(
|
|
4368
|
+
* null,
|
|
4369
|
+
* (store, tableId, hasTable) => {
|
|
4370
|
+
* console.log(`${tableId} table ` + (hasTable ? 'added' : 'removed'));
|
|
4371
|
+
* },
|
|
4372
|
+
* );
|
|
4373
|
+
*
|
|
4374
|
+
* store.delTable('pets');
|
|
4375
|
+
* // -> 'pets table removed'
|
|
4376
|
+
* store.setTable('species', {dog: {price: 5}});
|
|
4377
|
+
* // -> 'species table added'
|
|
4378
|
+
*
|
|
4379
|
+
* store.delListener(listenerId);
|
|
4380
|
+
* ```
|
|
4381
|
+
* @example
|
|
4382
|
+
* This example registers a listener that responds to a specific Table being
|
|
4383
|
+
* added or removed, and which also mutates the Store itself.
|
|
4384
|
+
*
|
|
4385
|
+
* ```js
|
|
4386
|
+
* const store = createStore().setTables({
|
|
4387
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4388
|
+
* });
|
|
4389
|
+
* const listenerId = store.addHasTableListener(
|
|
4390
|
+
* 'pets',
|
|
4391
|
+
* (store, tableId) => store.setCell('meta', 'update', tableId, true),
|
|
4392
|
+
* true,
|
|
4393
|
+
* );
|
|
4394
|
+
*
|
|
4395
|
+
* store.delTable('pets', 'fido');
|
|
4396
|
+
* console.log(store.getTable('meta'));
|
|
4397
|
+
* // -> {update: {pets: true}}
|
|
4398
|
+
*
|
|
4399
|
+
* store.delListener(listenerId);
|
|
4400
|
+
* ```
|
|
4401
|
+
* @category Listener
|
|
4402
|
+
* @since v4.4.0
|
|
4403
|
+
*/
|
|
4404
|
+
addHasTableListener(
|
|
4405
|
+
tableId: IdOrNull,
|
|
4406
|
+
listener: HasTableListener,
|
|
4407
|
+
mutator?: boolean,
|
|
4408
|
+
): Id;
|
|
4409
|
+
|
|
4048
4410
|
/**
|
|
4049
4411
|
* The addTableListener method registers a listener function with the Store
|
|
4050
4412
|
* that will be called whenever data in a Table changes.
|
|
@@ -4246,16 +4608,24 @@ export interface Store {
|
|
|
4246
4608
|
): Id;
|
|
4247
4609
|
|
|
4248
4610
|
/**
|
|
4249
|
-
* The
|
|
4250
|
-
* that will be called
|
|
4611
|
+
* The addHasTableCellListener method registers a listener function with the
|
|
4612
|
+
* Store that will be called when a Cell is added to or removed from anywhere
|
|
4613
|
+
* in a Table as a whole.
|
|
4251
4614
|
*
|
|
4252
|
-
* The provided listener is a
|
|
4253
|
-
* with a reference to the Store, the Id of the Table that changed, and
|
|
4254
|
-
*
|
|
4615
|
+
* The provided listener is a HasTableCellListener function, and will be
|
|
4616
|
+
* called with a reference to the Store, the Id of the Table that changed, and
|
|
4617
|
+
* the Id of the Table Cell that changed. It is also given a flag to indicate
|
|
4618
|
+
* whether the Cell now exists anywhere in the Table (having not done
|
|
4619
|
+
* previously), or does not (having done so previously).
|
|
4255
4620
|
*
|
|
4256
|
-
* You can either listen to a single Table
|
|
4257
|
-
*
|
|
4258
|
-
*
|
|
4621
|
+
* You can either listen to a single Table Cell being added or removed (by
|
|
4622
|
+
* specifying the Table Id and Cell Id, as the method's first two parameters)
|
|
4623
|
+
* or changes to any Table Cell (by providing `null` wildcards).
|
|
4624
|
+
*
|
|
4625
|
+
* Both, either, or neither of the `tableId` and `cellId` parameters can be
|
|
4626
|
+
* wildcarded with `null`. You can listen to a specific Row in a specific
|
|
4627
|
+
* Table, any Row in a specific Table, a specific Row in any Table, or any Row
|
|
4628
|
+
* in any Table.
|
|
4259
4629
|
*
|
|
4260
4630
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
4261
4631
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
@@ -4265,53 +4635,164 @@ export interface Store {
|
|
|
4265
4635
|
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4266
4636
|
* though they will fire non-mutator listeners.
|
|
4267
4637
|
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
4268
|
-
* @param
|
|
4269
|
-
*
|
|
4638
|
+
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
4639
|
+
* @param listener The function that will be called whenever the matching Cell
|
|
4640
|
+
* is added to or removed from anywhere in the Table.
|
|
4270
4641
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4271
4642
|
* Store data.
|
|
4272
4643
|
* @returns A unique Id for the listener that can later be used to call it
|
|
4273
4644
|
* explicitly, or to remove it.
|
|
4274
4645
|
* @example
|
|
4275
|
-
* This example registers a listener that responds to a
|
|
4276
|
-
*
|
|
4646
|
+
* This example registers a listener that responds to a specific Cell being
|
|
4647
|
+
* added to or removed from the Table as a whole.
|
|
4277
4648
|
*
|
|
4278
4649
|
* ```js
|
|
4279
|
-
* const store = createStore().setTables({
|
|
4280
|
-
*
|
|
4650
|
+
* const store = createStore().setTables({
|
|
4651
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4652
|
+
* });
|
|
4653
|
+
* const listenerId = store.addHasTableCellListener(
|
|
4281
4654
|
* 'pets',
|
|
4282
|
-
*
|
|
4283
|
-
*
|
|
4655
|
+
* 'color',
|
|
4656
|
+
* (store, tableId, cellId, hasTableCell) => {
|
|
4657
|
+
* console.log(
|
|
4658
|
+
* 'color cell in pets table ' + (hasTableCell ? 'added' : 'removed'),
|
|
4659
|
+
* );
|
|
4284
4660
|
* },
|
|
4285
4661
|
* );
|
|
4286
4662
|
*
|
|
4287
|
-
* store.
|
|
4288
|
-
* // -> '
|
|
4663
|
+
* store.delCell('pets', 'fido', 'color');
|
|
4664
|
+
* // -> 'color cell in pets table removed'
|
|
4665
|
+
*
|
|
4666
|
+
* store.setRow('pets', 'felix', {species: 'cat', color: 'brown'});
|
|
4667
|
+
* // -> 'color cell in pets table added'
|
|
4289
4668
|
*
|
|
4290
4669
|
* store.delListener(listenerId);
|
|
4291
4670
|
* ```
|
|
4292
4671
|
* @example
|
|
4293
|
-
* This example registers a listener that responds to any
|
|
4294
|
-
*
|
|
4672
|
+
* This example registers a listener that responds to any Cell being
|
|
4673
|
+
* added to or removed from the Table as a whole.
|
|
4295
4674
|
*
|
|
4296
4675
|
* ```js
|
|
4297
|
-
* const store = createStore().setTables({
|
|
4298
|
-
*
|
|
4676
|
+
* const store = createStore().setTables({
|
|
4677
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4678
|
+
* });
|
|
4679
|
+
* const listenerId = store.addHasTableCellListener(
|
|
4299
4680
|
* null,
|
|
4300
|
-
*
|
|
4301
|
-
*
|
|
4681
|
+
* null,
|
|
4682
|
+
* (store, tableId, cellId, hasTableCell) => {
|
|
4683
|
+
* console.log(
|
|
4684
|
+
* `${cellId} cell in ${tableId} table ` +
|
|
4685
|
+
* (hasTableCell ? 'added' : 'removed'),
|
|
4686
|
+
* );
|
|
4302
4687
|
* },
|
|
4303
4688
|
* );
|
|
4304
4689
|
*
|
|
4305
|
-
* store.
|
|
4306
|
-
* // -> '
|
|
4307
|
-
* store.
|
|
4308
|
-
* // -> '
|
|
4690
|
+
* store.delCell('pets', 'fido', 'color');
|
|
4691
|
+
* // -> 'color cell in pets table removed'
|
|
4692
|
+
* store.setTable('species', {dog: {price: 5}});
|
|
4693
|
+
* // -> 'price cell in species table added'
|
|
4309
4694
|
*
|
|
4310
4695
|
* store.delListener(listenerId);
|
|
4311
4696
|
* ```
|
|
4312
4697
|
* @example
|
|
4313
|
-
* This example registers a listener that responds to
|
|
4314
|
-
*
|
|
4698
|
+
* This example registers a listener that responds to a specific Cell being
|
|
4699
|
+
* added or removed, and which also mutates the Store itself.
|
|
4700
|
+
*
|
|
4701
|
+
* ```js
|
|
4702
|
+
* const store = createStore().setTables({
|
|
4703
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4704
|
+
* });
|
|
4705
|
+
* const listenerId = store.addHasTableCellListener(
|
|
4706
|
+
* 'pets',
|
|
4707
|
+
* 'color',
|
|
4708
|
+
* (store, tableId, cellId) =>
|
|
4709
|
+
* store.setCell('meta', 'update', `${tableId}_${cellId}`, true),
|
|
4710
|
+
* true,
|
|
4711
|
+
* );
|
|
4712
|
+
*
|
|
4713
|
+
* store.delRow('pets', 'fido');
|
|
4714
|
+
* console.log(store.getTable('meta'));
|
|
4715
|
+
* // -> {update: {pets_color: true}}
|
|
4716
|
+
*
|
|
4717
|
+
* store.delListener(listenerId);
|
|
4718
|
+
* ```
|
|
4719
|
+
* @category Listener
|
|
4720
|
+
* @since v4.4.0
|
|
4721
|
+
*/
|
|
4722
|
+
addHasTableCellListener(
|
|
4723
|
+
tableId: IdOrNull,
|
|
4724
|
+
cellId: IdOrNull,
|
|
4725
|
+
listener: HasTableCellListener,
|
|
4726
|
+
mutator?: boolean,
|
|
4727
|
+
): Id;
|
|
4728
|
+
|
|
4729
|
+
/**
|
|
4730
|
+
* The addRowCountListener method registers a listener function with the Store
|
|
4731
|
+
* that will be called whenever the count of Row objects in a Table change.
|
|
4732
|
+
*
|
|
4733
|
+
* The provided listener is a RowCountListener function, and will be called
|
|
4734
|
+
* with a reference to the Store, the Id of the Table that changed, and the
|
|
4735
|
+
* number of Row objects in the Table.
|
|
4736
|
+
*
|
|
4737
|
+
* You can either listen to a single Table (by specifying its Id as the
|
|
4738
|
+
* method's first parameter) or changes to any Table (by providing a `null`
|
|
4739
|
+
* wildcard).
|
|
4740
|
+
*
|
|
4741
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4742
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4743
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4744
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4745
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4746
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4747
|
+
* though they will fire non-mutator listeners.
|
|
4748
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
4749
|
+
* @param listener The function that will be called whenever the number of Row
|
|
4750
|
+
* objects in the Table changes.
|
|
4751
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4752
|
+
* Store data.
|
|
4753
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4754
|
+
* explicitly, or to remove it.
|
|
4755
|
+
* @example
|
|
4756
|
+
* This example registers a listener that responds to a change in the number
|
|
4757
|
+
* of Row objects in a specific Table.
|
|
4758
|
+
*
|
|
4759
|
+
* ```js
|
|
4760
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
4761
|
+
* const listenerId = store.addRowCountListener(
|
|
4762
|
+
* 'pets',
|
|
4763
|
+
* (store, _tableId, count) => {
|
|
4764
|
+
* console.log('Row count for pets table changed to ' + count);
|
|
4765
|
+
* },
|
|
4766
|
+
* );
|
|
4767
|
+
*
|
|
4768
|
+
* store.setRow('pets', 'felix', {species: 'cat'});
|
|
4769
|
+
* // -> 'Row count for pets table changed to 2'
|
|
4770
|
+
*
|
|
4771
|
+
* store.delListener(listenerId);
|
|
4772
|
+
* ```
|
|
4773
|
+
* @example
|
|
4774
|
+
* This example registers a listener that responds to any change to a change
|
|
4775
|
+
* in the number of Row objects of any Table.
|
|
4776
|
+
*
|
|
4777
|
+
* ```js
|
|
4778
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
4779
|
+
* const listenerId = store.addRowCountListener(
|
|
4780
|
+
* null,
|
|
4781
|
+
* (store, tableId, count) => {
|
|
4782
|
+
* console.log(`Row count for ${tableId} table changed to ${count}`);
|
|
4783
|
+
* },
|
|
4784
|
+
* );
|
|
4785
|
+
*
|
|
4786
|
+
* store.setRow('pets', 'felix', {species: 'cat'});
|
|
4787
|
+
* // -> 'Row count for pets table changed to 2'
|
|
4788
|
+
* store.setRow('species', 'dog', {price: 5});
|
|
4789
|
+
* // -> 'Row count for species table changed to 1'
|
|
4790
|
+
*
|
|
4791
|
+
* store.delListener(listenerId);
|
|
4792
|
+
* ```
|
|
4793
|
+
* @example
|
|
4794
|
+
* This example registers a listener that responds to any change to a change
|
|
4795
|
+
* in the number of Row objects of a specific Table, and which also mutates
|
|
4315
4796
|
* the Store itself.
|
|
4316
4797
|
*
|
|
4317
4798
|
* ```js
|
|
@@ -4654,6 +5135,123 @@ export interface Store {
|
|
|
4654
5135
|
mutator?: boolean,
|
|
4655
5136
|
): Id;
|
|
4656
5137
|
|
|
5138
|
+
/**
|
|
5139
|
+
* The addHasRowListener method registers a listener function with the Store
|
|
5140
|
+
* that will be called when a Row is added to or removed from the Store.
|
|
5141
|
+
*
|
|
5142
|
+
* The provided listener is a HasRowListener function, and will be called with
|
|
5143
|
+
* a reference to the Store, the Id of the Table that changed, and the Id of
|
|
5144
|
+
* the Row that changed. It is also given a flag to indicate whether the Row
|
|
5145
|
+
* now exists (having not done previously), or does not (having done so
|
|
5146
|
+
* previously).
|
|
5147
|
+
*
|
|
5148
|
+
* You can either listen to a single Row being added or removed (by specifying
|
|
5149
|
+
* the Table Id and Row Id, as the method's first two parameters) or changes
|
|
5150
|
+
* to any Row (by providing `null` wildcards).
|
|
5151
|
+
*
|
|
5152
|
+
* Both, either, or neither of the `tableId` and `rowId` parameters can be
|
|
5153
|
+
* wildcarded with `null`. You can listen to a specific Row in a specific
|
|
5154
|
+
* Table, any Row in a specific Table, a specific Row in any Table, or any Row
|
|
5155
|
+
* in any Table.
|
|
5156
|
+
*
|
|
5157
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
5158
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
5159
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
5160
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
5161
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
5162
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
5163
|
+
* though they will fire non-mutator listeners.
|
|
5164
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
5165
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
5166
|
+
* @param listener The function that will be called whenever the matching Row
|
|
5167
|
+
* is added or removed.
|
|
5168
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5169
|
+
* Store data.
|
|
5170
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
5171
|
+
* explicitly, or to remove it.
|
|
5172
|
+
* @example
|
|
5173
|
+
* This example registers a listener that responds to a specific Row being
|
|
5174
|
+
* added or removed.
|
|
5175
|
+
*
|
|
5176
|
+
* ```js
|
|
5177
|
+
* const store = createStore().setTables({
|
|
5178
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5179
|
+
* });
|
|
5180
|
+
* const listenerId = store.addHasRowListener(
|
|
5181
|
+
* 'pets',
|
|
5182
|
+
* 'fido',
|
|
5183
|
+
* (store, tableId, rowId, hasRow) => {
|
|
5184
|
+
* console.log(
|
|
5185
|
+
* 'fido row in pets table ' + (hasRow ? 'added' : 'removed'),
|
|
5186
|
+
* );
|
|
5187
|
+
* },
|
|
5188
|
+
* );
|
|
5189
|
+
*
|
|
5190
|
+
* store.delRow('pets', 'fido');
|
|
5191
|
+
* // -> 'fido row in pets table removed'
|
|
5192
|
+
*
|
|
5193
|
+
* store.setRow('pets', 'fido', {species: 'dog', color: 'brown'});
|
|
5194
|
+
* // -> 'fido row in pets table added'
|
|
5195
|
+
*
|
|
5196
|
+
* store.delListener(listenerId);
|
|
5197
|
+
* ```
|
|
5198
|
+
* @example
|
|
5199
|
+
* This example registers a listener that responds to any Row being added or
|
|
5200
|
+
* removed.
|
|
5201
|
+
*
|
|
5202
|
+
* ```js
|
|
5203
|
+
* const store = createStore().setTables({
|
|
5204
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5205
|
+
* });
|
|
5206
|
+
* const listenerId = store.addHasRowListener(
|
|
5207
|
+
* null,
|
|
5208
|
+
* null,
|
|
5209
|
+
* (store, tableId, rowId, hasRow) => {
|
|
5210
|
+
* console.log(
|
|
5211
|
+
* `${rowId} row in ${tableId} table ` + (hasRow ? 'added' : 'removed'),
|
|
5212
|
+
* );
|
|
5213
|
+
* },
|
|
5214
|
+
* );
|
|
5215
|
+
*
|
|
5216
|
+
* store.delRow('pets', 'fido');
|
|
5217
|
+
* // -> 'fido row in pets table removed'
|
|
5218
|
+
* store.setTable('species', {dog: {price: 5}});
|
|
5219
|
+
* // -> 'dog row in species table added'
|
|
5220
|
+
*
|
|
5221
|
+
* store.delListener(listenerId);
|
|
5222
|
+
* ```
|
|
5223
|
+
* @example
|
|
5224
|
+
* This example registers a listener that responds to a specific Row being
|
|
5225
|
+
* added or removed, and which also mutates the Store itself.
|
|
5226
|
+
*
|
|
5227
|
+
* ```js
|
|
5228
|
+
* const store = createStore().setTables({
|
|
5229
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5230
|
+
* });
|
|
5231
|
+
* const listenerId = store.addHasRowListener(
|
|
5232
|
+
* 'pets',
|
|
5233
|
+
* 'fido',
|
|
5234
|
+
* (store, tableId, rowId) =>
|
|
5235
|
+
* store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
|
|
5236
|
+
* true,
|
|
5237
|
+
* );
|
|
5238
|
+
*
|
|
5239
|
+
* store.delRow('pets', 'fido');
|
|
5240
|
+
* console.log(store.getTable('meta'));
|
|
5241
|
+
* // -> {update: {pets_fido: true}}
|
|
5242
|
+
*
|
|
5243
|
+
* store.delListener(listenerId);
|
|
5244
|
+
* ```
|
|
5245
|
+
* @category Listener
|
|
5246
|
+
* @since v4.4.0
|
|
5247
|
+
*/
|
|
5248
|
+
addHasRowListener(
|
|
5249
|
+
tableId: IdOrNull,
|
|
5250
|
+
rowId: IdOrNull,
|
|
5251
|
+
listener: HasRowListener,
|
|
5252
|
+
mutator?: boolean,
|
|
5253
|
+
): Id;
|
|
5254
|
+
|
|
4657
5255
|
/**
|
|
4658
5256
|
* The addRowListener method registers a listener function with the Store that
|
|
4659
5257
|
* will be called whenever data in a Row changes.
|
|
@@ -4868,6 +5466,130 @@ export interface Store {
|
|
|
4868
5466
|
mutator?: boolean,
|
|
4869
5467
|
): Id;
|
|
4870
5468
|
|
|
5469
|
+
/**
|
|
5470
|
+
* The addHasCellListener method registers a listener function with the Store
|
|
5471
|
+
* that will be called when a Cell is added to or removed from the Store.
|
|
5472
|
+
*
|
|
5473
|
+
* The provided listener is a HasCellListener function, and will be called
|
|
5474
|
+
* with a reference to the Store, the Id of the Table that changed, the Id of
|
|
5475
|
+
* the Row that changed, and the Id of the Cell that changed. It is also given
|
|
5476
|
+
* a flag to indicate whether the Cell now exists (having not done
|
|
5477
|
+
* previously), or does not (having done so previously).
|
|
5478
|
+
*
|
|
5479
|
+
* You can either listen to a single Cell being added or removed (by
|
|
5480
|
+
* specifying the Table Id, Row Id, and Cell Id as the method's first three
|
|
5481
|
+
* parameters) or changes to any Cell (by providing `null` wildcards).
|
|
5482
|
+
*
|
|
5483
|
+
* All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
|
|
5484
|
+
* be wildcarded with `null`. You can listen to a specific Cell in a specific
|
|
5485
|
+
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
5486
|
+
* every other combination of wildcards.
|
|
5487
|
+
*
|
|
5488
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
5489
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
5490
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
5491
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
5492
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
5493
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
5494
|
+
* though they will fire non-mutator listeners.
|
|
5495
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
5496
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
5497
|
+
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
5498
|
+
* @param listener The function that will be called whenever the matching Cell
|
|
5499
|
+
* is added or removed.
|
|
5500
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5501
|
+
* Store data.
|
|
5502
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
5503
|
+
* explicitly, or to remove it.
|
|
5504
|
+
* @example
|
|
5505
|
+
* This example registers a listener that responds to a specific Cell being
|
|
5506
|
+
* added or removed.
|
|
5507
|
+
*
|
|
5508
|
+
* ```js
|
|
5509
|
+
* const store = createStore().setTables({
|
|
5510
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5511
|
+
* });
|
|
5512
|
+
* const listenerId = store.addHasCellListener(
|
|
5513
|
+
* 'pets',
|
|
5514
|
+
* 'fido',
|
|
5515
|
+
* 'color',
|
|
5516
|
+
* (store, tableId, rowId, cellId, hasCell) => {
|
|
5517
|
+
* console.log(
|
|
5518
|
+
* 'color cell in fido row in pets table ' +
|
|
5519
|
+
* (hasCell ? 'added' : 'removed'),
|
|
5520
|
+
* );
|
|
5521
|
+
* },
|
|
5522
|
+
* );
|
|
5523
|
+
*
|
|
5524
|
+
* store.delCell('pets', 'fido', 'color');
|
|
5525
|
+
* // -> 'color cell in fido row in pets table removed'
|
|
5526
|
+
*
|
|
5527
|
+
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
5528
|
+
* // -> 'color cell in fido row in pets table added'
|
|
5529
|
+
*
|
|
5530
|
+
* store.delListener(listenerId);
|
|
5531
|
+
* ```
|
|
5532
|
+
* @example
|
|
5533
|
+
* This example registers a listener that responds to any Cell being added or
|
|
5534
|
+
* removed.
|
|
5535
|
+
*
|
|
5536
|
+
* ```js
|
|
5537
|
+
* const store = createStore().setTables({
|
|
5538
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5539
|
+
* });
|
|
5540
|
+
* const listenerId = store.addHasCellListener(
|
|
5541
|
+
* null,
|
|
5542
|
+
* null,
|
|
5543
|
+
* null,
|
|
5544
|
+
* (store, tableId, rowId, cellId, hasCell) => {
|
|
5545
|
+
* console.log(
|
|
5546
|
+
* `${cellId} cell in ${rowId} row in ${tableId} table ` +
|
|
5547
|
+
* (hasCell ? 'added' : 'removed'),
|
|
5548
|
+
* );
|
|
5549
|
+
* },
|
|
5550
|
+
* );
|
|
5551
|
+
*
|
|
5552
|
+
* store.delCell('pets', 'fido', 'color');
|
|
5553
|
+
* // -> 'color cell in fido row in pets table removed'
|
|
5554
|
+
* store.setTable('species', {dog: {price: 5}});
|
|
5555
|
+
* // -> 'price cell in dog row in species table added'
|
|
5556
|
+
*
|
|
5557
|
+
* store.delListener(listenerId);
|
|
5558
|
+
* ```
|
|
5559
|
+
* @example
|
|
5560
|
+
* This example registers a listener that responds to a specific Cell being
|
|
5561
|
+
* added or removed, and which also mutates the Store itself.
|
|
5562
|
+
*
|
|
5563
|
+
* ```js
|
|
5564
|
+
* const store = createStore().setTables({
|
|
5565
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
5566
|
+
* });
|
|
5567
|
+
* const listenerId = store.addHasCellListener(
|
|
5568
|
+
* 'pets',
|
|
5569
|
+
* 'fido',
|
|
5570
|
+
* 'color',
|
|
5571
|
+
* (store, tableId, rowId, cellId) =>
|
|
5572
|
+
* store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
|
|
5573
|
+
* true,
|
|
5574
|
+
* );
|
|
5575
|
+
*
|
|
5576
|
+
* store.delCell('pets', 'fido', 'color');
|
|
5577
|
+
* console.log(store.getTable('meta'));
|
|
5578
|
+
* // -> {update: {pets_fido_color: true}}
|
|
5579
|
+
*
|
|
5580
|
+
* store.delListener(listenerId);
|
|
5581
|
+
* ```
|
|
5582
|
+
* @category Listener
|
|
5583
|
+
* @since v4.4.0
|
|
5584
|
+
*/
|
|
5585
|
+
addHasCellListener(
|
|
5586
|
+
tableId: IdOrNull,
|
|
5587
|
+
rowId: IdOrNull,
|
|
5588
|
+
cellId: IdOrNull,
|
|
5589
|
+
listener: HasCellListener,
|
|
5590
|
+
mutator?: boolean,
|
|
5591
|
+
): Id;
|
|
5592
|
+
|
|
4871
5593
|
/**
|
|
4872
5594
|
* The addCellListener method registers a listener function with the Store
|
|
4873
5595
|
* that will be called whenever data in a Cell changes.
|
|
@@ -4987,6 +5709,69 @@ export interface Store {
|
|
|
4987
5709
|
mutator?: boolean,
|
|
4988
5710
|
): Id;
|
|
4989
5711
|
|
|
5712
|
+
/**
|
|
5713
|
+
* The addHasValuesListener method registers a listener function with the
|
|
5714
|
+
* Store that will be called when Values as a whole are added to or removed
|
|
5715
|
+
* from the Store.
|
|
5716
|
+
*
|
|
5717
|
+
* The provided listener is a HasValuesListener function, and will be called
|
|
5718
|
+
* with a reference to the Store. It is also given a flag to indicate whether
|
|
5719
|
+
* Values now exist (having not done previously), or do not (having done so
|
|
5720
|
+
* previously).
|
|
5721
|
+
*
|
|
5722
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
5723
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
5724
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
5725
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
5726
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
5727
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
5728
|
+
* though they will fire non-mutator listeners.
|
|
5729
|
+
* @param listener The function that will be called whenever Values as a whole
|
|
5730
|
+
* are added or removed.
|
|
5731
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5732
|
+
* Store data.
|
|
5733
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
5734
|
+
* explicitly, or to remove it.
|
|
5735
|
+
* @example
|
|
5736
|
+
* This example registers a listener that responds to Values being added or
|
|
5737
|
+
* removed.
|
|
5738
|
+
*
|
|
5739
|
+
* ```js
|
|
5740
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
5741
|
+
* const listenerId = store.addHasValuesListener((store, hasValues) => {
|
|
5742
|
+
* console.log('Values ' + (hasValues ? 'added' : 'removed'));
|
|
5743
|
+
* });
|
|
5744
|
+
*
|
|
5745
|
+
* store.delValues();
|
|
5746
|
+
* // -> 'Values removed'
|
|
5747
|
+
*
|
|
5748
|
+
* store.setValue('employees', 4);
|
|
5749
|
+
* // -> 'Values added'
|
|
5750
|
+
*
|
|
5751
|
+
* store.delListener(listenerId);
|
|
5752
|
+
* ```
|
|
5753
|
+
* @example
|
|
5754
|
+
* This example registers a listener that responds to Values being added or
|
|
5755
|
+
* removed, and which also mutates the Store itself.
|
|
5756
|
+
*
|
|
5757
|
+
* ```js
|
|
5758
|
+
* const store = createStore();
|
|
5759
|
+
* const listenerId = store.addHasValuesListener(
|
|
5760
|
+
* (store, hasValues) => store.setValue('hasValues', hasValues),
|
|
5761
|
+
* true,
|
|
5762
|
+
* );
|
|
5763
|
+
*
|
|
5764
|
+
* store.setValue('employees', 4);
|
|
5765
|
+
* console.log(store.getValues());
|
|
5766
|
+
* // -> {employees: 4, hasValues: true}
|
|
5767
|
+
*
|
|
5768
|
+
* store.delListener(listenerId);
|
|
5769
|
+
* ```
|
|
5770
|
+
* @category Listener
|
|
5771
|
+
* @since v4.4.0
|
|
5772
|
+
*/
|
|
5773
|
+
addHasValuesListener(listener: HasValuesListener, mutator?: boolean): Id;
|
|
5774
|
+
|
|
4990
5775
|
/**
|
|
4991
5776
|
* The addValuesListener method registers a listener function with the Store
|
|
4992
5777
|
* that will be called whenever the Values change.
|
|
@@ -5110,6 +5895,101 @@ export interface Store {
|
|
|
5110
5895
|
*/
|
|
5111
5896
|
addValueIdsListener(listener: ValueIdsListener, mutator?: boolean): Id;
|
|
5112
5897
|
|
|
5898
|
+
/**
|
|
5899
|
+
* The addHasValueListener method registers a listener function with the Store
|
|
5900
|
+
* that will be called when a Value is added to or removed from the Store.
|
|
5901
|
+
*
|
|
5902
|
+
* The provided listener is a HasValueListener function, and will be called
|
|
5903
|
+
* with a reference to the Store and the Id of Value that changed. It is also
|
|
5904
|
+
* given a flag to indicate whether the Value now exists (having not done
|
|
5905
|
+
* previously), or does not (having done so previously).
|
|
5906
|
+
*
|
|
5907
|
+
* You can either listen to a single Value being added or removed (by
|
|
5908
|
+
* specifying the Value Id) or any Value being added or removed (by providing
|
|
5909
|
+
* a `null` wildcard).
|
|
5910
|
+
*
|
|
5911
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
5912
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
5913
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
5914
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
5915
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
5916
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
5917
|
+
* though they will fire non-mutator listeners.
|
|
5918
|
+
* @param valueId The Id of the Value to listen to, or `null` as a wildcard.
|
|
5919
|
+
* @param listener The function that will be called whenever the matching
|
|
5920
|
+
* Value is added or removed.
|
|
5921
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5922
|
+
* Store data.
|
|
5923
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
5924
|
+
* explicitly, or to remove it.
|
|
5925
|
+
* @example
|
|
5926
|
+
* This example registers a listener that responds to a specific Value being
|
|
5927
|
+
* added or removed.
|
|
5928
|
+
*
|
|
5929
|
+
* ```js
|
|
5930
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
5931
|
+
* const listenerId = store.addHasValueListener(
|
|
5932
|
+
* 'employees',
|
|
5933
|
+
* (store, valueId, hasValue) => {
|
|
5934
|
+
* console.log('employee value ' + (hasValue ? 'added' : 'removed'));
|
|
5935
|
+
* },
|
|
5936
|
+
* );
|
|
5937
|
+
*
|
|
5938
|
+
* store.delValue('employees');
|
|
5939
|
+
* // -> 'employee value removed'
|
|
5940
|
+
*
|
|
5941
|
+
* store.setValue('employees', 4);
|
|
5942
|
+
* // -> 'employee value added'
|
|
5943
|
+
*
|
|
5944
|
+
* store.delListener(listenerId);
|
|
5945
|
+
* ```
|
|
5946
|
+
* @example
|
|
5947
|
+
* This example registers a listener that responds to any Value being added or
|
|
5948
|
+
* removed.
|
|
5949
|
+
*
|
|
5950
|
+
* ```js
|
|
5951
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
5952
|
+
* const listenerId = store.addHasValueListener(
|
|
5953
|
+
* null,
|
|
5954
|
+
* (store, valueId, hasValue) => {
|
|
5955
|
+
* console.log(valueId + ' value ' + (hasValue ? 'added' : 'removed'));
|
|
5956
|
+
* },
|
|
5957
|
+
* );
|
|
5958
|
+
*
|
|
5959
|
+
* store.delValue('employees');
|
|
5960
|
+
* // -> 'employees value removed'
|
|
5961
|
+
* store.setValue('website', 'https://pets.com');
|
|
5962
|
+
* // -> 'website value added'
|
|
5963
|
+
*
|
|
5964
|
+
* store.delListener(listenerId);
|
|
5965
|
+
* ```
|
|
5966
|
+
* @example
|
|
5967
|
+
* This example registers a listener that responds to a specific Value being
|
|
5968
|
+
* added or removed, and which also mutates the Store itself.
|
|
5969
|
+
*
|
|
5970
|
+
* ```js
|
|
5971
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
5972
|
+
* const listenerId = store.addHasValueListener(
|
|
5973
|
+
* 'employees',
|
|
5974
|
+
* (store, valueId) => store.setValue('updated', true),
|
|
5975
|
+
* true,
|
|
5976
|
+
* );
|
|
5977
|
+
*
|
|
5978
|
+
* store.delValue('employees');
|
|
5979
|
+
* console.log(store.getValues());
|
|
5980
|
+
* // -> {open: true, updated: true}
|
|
5981
|
+
*
|
|
5982
|
+
* store.delListener(listenerId);
|
|
5983
|
+
* ```
|
|
5984
|
+
* @category Listener
|
|
5985
|
+
* @since v4.4.0
|
|
5986
|
+
*/
|
|
5987
|
+
addHasValueListener(
|
|
5988
|
+
valueId: IdOrNull,
|
|
5989
|
+
listener: HasValueListener,
|
|
5990
|
+
mutator?: boolean,
|
|
5991
|
+
): Id;
|
|
5992
|
+
|
|
5113
5993
|
/**
|
|
5114
5994
|
* The addValueListener method registers a listener function with the Store
|
|
5115
5995
|
* that will be called whenever data in a Value changes.
|