tinybase 1.3.6 → 2.0.0-beta.2
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/checkpoints.d.ts +4 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +4 -3
- package/lib/debug/checkpoints.js +69 -56
- package/lib/debug/indexes.d.ts +4 -2
- package/lib/debug/indexes.js +106 -69
- package/lib/debug/metrics.d.ts +1 -1
- package/lib/debug/metrics.js +187 -131
- package/lib/debug/persisters.d.ts +6 -0
- package/lib/debug/persisters.js +2 -1
- package/lib/debug/queries.d.ts +3251 -0
- package/lib/debug/queries.js +900 -0
- package/lib/debug/relationships.d.ts +12 -10
- package/lib/debug/relationships.js +104 -68
- package/lib/debug/store.d.ts +415 -74
- package/lib/debug/store.js +295 -120
- package/lib/debug/tinybase.d.ts +1 -0
- package/lib/debug/tinybase.js +985 -176
- package/lib/debug/ui-react.d.ts +4325 -1754
- package/lib/debug/ui-react.js +413 -85
- package/lib/indexes.d.ts +4 -2
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +6 -0
- package/lib/queries.d.ts +3251 -0
- package/lib/queries.js +1 -0
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +12 -10
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +415 -74
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +1 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +4325 -1754
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -0
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- 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.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +4 -4
- package/readme.md +2 -2
package/lib/store.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export type Cell = string | number | boolean;
|
|
|
94
94
|
*
|
|
95
95
|
* This is used when describing a Cell that is present _or_ that is not present
|
|
96
96
|
* - such as when it has been deleted, or when describing a previous state where
|
|
97
|
-
*
|
|
97
|
+
* the Cell value has since been added.
|
|
98
98
|
*
|
|
99
99
|
* @category Store
|
|
100
100
|
*/
|
|
@@ -284,6 +284,35 @@ export type TableListener = (
|
|
|
284
284
|
*/
|
|
285
285
|
export type RowIdsListener = (store: Store, tableId: Id) => void;
|
|
286
286
|
|
|
287
|
+
/**
|
|
288
|
+
* The SortedRowIdsListener type describes a function that is used to listen to
|
|
289
|
+
* changes to sorted Row Ids in a Table.
|
|
290
|
+
*
|
|
291
|
+
* A SortedRowIdsListener is provided when using the addSortedRowIdsListener
|
|
292
|
+
* method. See that method for specific examples.
|
|
293
|
+
*
|
|
294
|
+
* When called, a SortedRowIdsListener is given a reference to the Store, the Id
|
|
295
|
+
* of the Table whose Row Ids sorting changed, the Cell Id being used to sort
|
|
296
|
+
* them, and whether descending or not. It also receives the sorted array of Ids
|
|
297
|
+
* itself, so that you can use them in the listener without the additional cost
|
|
298
|
+
* of an explicit call to getSortedRowIds.
|
|
299
|
+
*
|
|
300
|
+
* @param store A reference to the Store that changed.
|
|
301
|
+
* @param tableId The Id of the Table whose sorted Row Ids changed.
|
|
302
|
+
* @param cellId The Id of the Cell whose values were used for the sorting.
|
|
303
|
+
* @param descending Whether the sorting was in descending order.
|
|
304
|
+
* @param sortedRowIds The sorted Row Ids themselves.
|
|
305
|
+
* @category Listener
|
|
306
|
+
* @since v2.0.0
|
|
307
|
+
*/
|
|
308
|
+
export type SortedRowIdsListener = (
|
|
309
|
+
store: Store,
|
|
310
|
+
tableId: Id,
|
|
311
|
+
cellId: Id | undefined,
|
|
312
|
+
descending: boolean,
|
|
313
|
+
sortedRowIds: Ids,
|
|
314
|
+
) => void;
|
|
315
|
+
|
|
287
316
|
/**
|
|
288
317
|
* The RowListener type describes a function that is used to listen to changes
|
|
289
318
|
* to a Row.
|
|
@@ -327,7 +356,6 @@ export type RowListener = (
|
|
|
327
356
|
* @param store A reference to the Store that changed.
|
|
328
357
|
* @param tableId The Id of the Table that changed.
|
|
329
358
|
* @param rowId The Id of the Row that changed.
|
|
330
|
-
* changes.
|
|
331
359
|
* @category Listener
|
|
332
360
|
*/
|
|
333
361
|
export type CellIdsListener = (store: Store, tableId: Id, rowId: Id) => void;
|
|
@@ -421,9 +449,9 @@ export type GetCellChange = (tableId: Id, rowId: Id, cellId: Id) => CellChange;
|
|
|
421
449
|
* The CellChange type describes a Cell's changes during a transaction.
|
|
422
450
|
*
|
|
423
451
|
* This is returned by the GetCellChange function that is provided to every
|
|
424
|
-
* listener when called. This array contains the previous value of a Cell
|
|
425
|
-
*
|
|
426
|
-
*
|
|
452
|
+
* listener when called. This array contains the previous value of a Cell before
|
|
453
|
+
* the current transaction, the new value after it, and a convenience flag that
|
|
454
|
+
* indicates that the value has changed.
|
|
427
455
|
*
|
|
428
456
|
* @category Listener
|
|
429
457
|
*/
|
|
@@ -540,9 +568,9 @@ export type ChangedCells = {
|
|
|
540
568
|
* the transaction method. See that method for specific examples.
|
|
541
569
|
*
|
|
542
570
|
* This type is a nested structure of Table, Row, and Cell objects, much like
|
|
543
|
-
* the Tables object, but one for which Cell values are listed in array
|
|
544
|
-
*
|
|
545
|
-
*
|
|
571
|
+
* the Tables object, but one for which Cell values are listed in array (much
|
|
572
|
+
* like the InvalidCellListener type) so that multiple failed attempts to change
|
|
573
|
+
* a Cell during the transaction are described.
|
|
546
574
|
*
|
|
547
575
|
* @category Transaction
|
|
548
576
|
* @since v1.2.0
|
|
@@ -568,39 +596,43 @@ export type InvalidCells = {
|
|
|
568
596
|
*/
|
|
569
597
|
export type StoreListenerStats = {
|
|
570
598
|
/**
|
|
571
|
-
* The number of
|
|
599
|
+
* The number of TablesListener functions registered with the Store.
|
|
572
600
|
*/
|
|
573
601
|
tables?: number;
|
|
574
602
|
/**
|
|
575
|
-
* The number of
|
|
603
|
+
* The number of TableIdsListener functions registered with the Store.
|
|
576
604
|
*/
|
|
577
605
|
tableIds?: number;
|
|
578
606
|
/**
|
|
579
|
-
* The number of
|
|
607
|
+
* The number of TableListener functions registered with the Store.
|
|
580
608
|
*/
|
|
581
609
|
table?: number;
|
|
582
610
|
/**
|
|
583
|
-
* The number of
|
|
611
|
+
* The number of RowIdsListener functions registered with the Store.
|
|
584
612
|
*/
|
|
585
613
|
rowIds?: number;
|
|
586
614
|
/**
|
|
587
|
-
* The number of
|
|
615
|
+
* The number of SortedRowIdsListener functions registered with the Store.
|
|
616
|
+
*/
|
|
617
|
+
sortedRowIds?: number;
|
|
618
|
+
/**
|
|
619
|
+
* The number of RowListener functions registered with the Store.
|
|
588
620
|
*/
|
|
589
621
|
row?: number;
|
|
590
622
|
/**
|
|
591
|
-
* The number of
|
|
623
|
+
* The number of CellIdsListener functions registered with the Store.
|
|
592
624
|
*/
|
|
593
625
|
cellIds?: number;
|
|
594
626
|
/**
|
|
595
|
-
* The number of
|
|
627
|
+
* The number of CellListener functions registered with the Store.
|
|
596
628
|
*/
|
|
597
629
|
cell?: number;
|
|
598
630
|
/**
|
|
599
|
-
* The number of
|
|
631
|
+
* The number of InvalidCellListener functions registered with the Store.
|
|
600
632
|
*/
|
|
601
633
|
invalidCell?: number;
|
|
602
634
|
/**
|
|
603
|
-
* The number of
|
|
635
|
+
* The number of TransactionListener functions registered with the Store.
|
|
604
636
|
*/
|
|
605
637
|
transaction?: number;
|
|
606
638
|
};
|
|
@@ -667,6 +699,7 @@ export type StoreListenerStats = {
|
|
|
667
699
|
* |Table Ids|getTableIds|-|-|addTableIdsListener|
|
|
668
700
|
* |Table|getTable|setTable|delTable|addTableListener|
|
|
669
701
|
* |Row Ids|getRowIds|-|-|addRowIdsListener|
|
|
702
|
+
* |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
|
|
670
703
|
* |Row|getRow|setRow|delRow|addRowListener|
|
|
671
704
|
* |Cell Ids|getCellIds|-|-|addCellIdsListener|
|
|
672
705
|
* |Cell|getCell|setCell|delCell|addCellListener|
|
|
@@ -794,9 +827,9 @@ export interface Store {
|
|
|
794
827
|
* The getTableIds method returns the Ids of every Table in the Store.
|
|
795
828
|
*
|
|
796
829
|
* Note that this returns a copy of, rather than a reference, to the list of
|
|
797
|
-
* Ids, so changes made to the list are not made to the Store itself.
|
|
798
|
-
* the order
|
|
799
|
-
*
|
|
830
|
+
* Ids, so changes made to the list are not made to the Store itself. Since
|
|
831
|
+
* v2.0.0, the order is significant: this method will return the Ids in the
|
|
832
|
+
* order in which each Table was added.
|
|
800
833
|
*
|
|
801
834
|
* @returns An array of the Ids of every Table in the Store.
|
|
802
835
|
* @example
|
|
@@ -861,9 +894,9 @@ export interface Store {
|
|
|
861
894
|
* The getRowIds method returns the Ids of every Row in a given Table.
|
|
862
895
|
*
|
|
863
896
|
* Note that this returns a copy of, rather than a reference, to the list of
|
|
864
|
-
* Ids, so changes made to the list are not made to the Store itself.
|
|
865
|
-
* the order
|
|
866
|
-
*
|
|
897
|
+
* Ids, so changes made to the list are not made to the Store itself. Since
|
|
898
|
+
* v2.0.0, the order is significant: this method will return the Ids in the
|
|
899
|
+
* order in which each Row was added.
|
|
867
900
|
*
|
|
868
901
|
* @param tableId The Id of the Table in the Store.
|
|
869
902
|
* @returns An array of the Ids of every Row in the Table.
|
|
@@ -893,6 +926,82 @@ export interface Store {
|
|
|
893
926
|
*/
|
|
894
927
|
getRowIds(tableId: Id): Ids;
|
|
895
928
|
|
|
929
|
+
/**
|
|
930
|
+
* The getSortedRowIds method returns the Ids of every Row in a given Table,
|
|
931
|
+
* sorted according to the values in a specified Cell.
|
|
932
|
+
*
|
|
933
|
+
* The sorting of the rows is alphanumeric, and you can indicate whether it
|
|
934
|
+
* should be in descending order.
|
|
935
|
+
*
|
|
936
|
+
* Note that every call to this method will perform the sorting afresh - there
|
|
937
|
+
* is no caching of the results - and so you are advised to memoize the
|
|
938
|
+
* results yourself, especially when the Table is large. For a performant
|
|
939
|
+
* approach to tracking the sorted Row Ids when they change, use the
|
|
940
|
+
* addSortedRowIdsListener method.
|
|
941
|
+
*
|
|
942
|
+
* If the Table does not exist, an empty array is returned.
|
|
943
|
+
*
|
|
944
|
+
* @param tableId The Id of the Table in the Store.
|
|
945
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
946
|
+
* `undefined` to by sort the Row Id itself.
|
|
947
|
+
* @param descending Whether the sorting should be in descending order.
|
|
948
|
+
* @returns An array of the sorted Ids of every Row in the Table.
|
|
949
|
+
* @example
|
|
950
|
+
* This example retrieves sorted Row Ids in a Table.
|
|
951
|
+
*
|
|
952
|
+
* ```js
|
|
953
|
+
* const store = createStore().setTables({
|
|
954
|
+
* pets: {
|
|
955
|
+
* fido: {species: 'dog'},
|
|
956
|
+
* felix: {species: 'cat'},
|
|
957
|
+
* },
|
|
958
|
+
* });
|
|
959
|
+
* console.log(store.getSortedRowIds('pets', 'species'));
|
|
960
|
+
* // -> ['felix', 'fido']
|
|
961
|
+
* ```
|
|
962
|
+
* @example
|
|
963
|
+
* This example retrieves sorted Row Ids in a Table in reverse order.
|
|
964
|
+
*
|
|
965
|
+
* ```js
|
|
966
|
+
* const store = createStore().setTables({
|
|
967
|
+
* pets: {
|
|
968
|
+
* fido: {species: 'dog'},
|
|
969
|
+
* felix: {species: 'cat'},
|
|
970
|
+
* cujo: {species: 'wolf'},
|
|
971
|
+
* },
|
|
972
|
+
* });
|
|
973
|
+
* console.log(store.getSortedRowIds('pets', 'species', true));
|
|
974
|
+
* // -> ['cujo', 'fido', 'felix']
|
|
975
|
+
* ```
|
|
976
|
+
* @example
|
|
977
|
+
* This example retrieves Row Ids sorted by their own value, since the
|
|
978
|
+
* `cellId` parameter is undefined.
|
|
979
|
+
*
|
|
980
|
+
* ```js
|
|
981
|
+
* const store = createStore().setTables({
|
|
982
|
+
* pets: {
|
|
983
|
+
* fido: {species: 'dog'},
|
|
984
|
+
* felix: {species: 'cat'},
|
|
985
|
+
* cujo: {species: 'wolf'},
|
|
986
|
+
* },
|
|
987
|
+
* });
|
|
988
|
+
* console.log(store.getSortedRowIds('pets'));
|
|
989
|
+
* // -> ['cujo', 'felix', 'fido']
|
|
990
|
+
* ```
|
|
991
|
+
* @example
|
|
992
|
+
* This example retrieves the sorted Row Ids of a Table that does not exist,
|
|
993
|
+
* returning an empty array.
|
|
994
|
+
*
|
|
995
|
+
* ```js
|
|
996
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
997
|
+
* console.log(store.getSortedRowIds('employees'));
|
|
998
|
+
* // -> []
|
|
999
|
+
* ```
|
|
1000
|
+
* @category Getter
|
|
1001
|
+
* @since v2.0.0
|
|
1002
|
+
*/
|
|
1003
|
+
getSortedRowIds(tableId: Id, cellId?: Id, descending?: boolean): Ids;
|
|
1004
|
+
|
|
896
1005
|
/**
|
|
897
1006
|
* The getRow method returns an object containing the entire data of a single
|
|
898
1007
|
* Row in a given Table.
|
|
@@ -935,9 +1044,9 @@ export interface Store {
|
|
|
935
1044
|
* given Table.
|
|
936
1045
|
*
|
|
937
1046
|
* Note that this returns a copy of, rather than a reference, to the list of
|
|
938
|
-
* Ids, so changes made to the list are not made to the Store itself.
|
|
939
|
-
* the order
|
|
940
|
-
*
|
|
1047
|
+
* Ids, so changes made to the list are not made to the Store itself. Since
|
|
1048
|
+
* v2.0.0, the order is significant: this method will return the Ids in the
|
|
1049
|
+
* order in which each Cell was added.
|
|
941
1050
|
*
|
|
942
1051
|
* @param tableId The Id of the Table in the Store.
|
|
943
1052
|
* @param rowId The Id of the Row in the Table.
|
|
@@ -968,17 +1077,13 @@ export interface Store {
|
|
|
968
1077
|
getCellIds(tableId: Id, rowId: Id): Ids;
|
|
969
1078
|
|
|
970
1079
|
/**
|
|
971
|
-
* The getCell method returns
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
* Note that this returns a copy of, rather than a reference to the underlying
|
|
975
|
-
* data, so changes made to the returned object are not made to the Store
|
|
976
|
-
* itself.
|
|
1080
|
+
* The getCell method returns the value of a single Cell in a given Row, in a
|
|
1081
|
+
* given Table.
|
|
977
1082
|
*
|
|
978
1083
|
* @param tableId The Id of the Table in the Store.
|
|
979
1084
|
* @param rowId The Id of the Row in the Table.
|
|
980
1085
|
* @param cellId The Id of the Cell in the Row.
|
|
981
|
-
* @returns The value of the Cell
|
|
1086
|
+
* @returns The value of the Cell, or `undefined`.
|
|
982
1087
|
* @example
|
|
983
1088
|
* This example retrieves a single Cell.
|
|
984
1089
|
*
|
|
@@ -2100,12 +2205,19 @@ export interface Store {
|
|
|
2100
2205
|
* The addTableIdsListener method registers a listener function with the Store
|
|
2101
2206
|
* that will be called whenever the Table Ids in the Store change.
|
|
2102
2207
|
*
|
|
2103
|
-
* Such a listener is only called when a Table is added or removed. To listen
|
|
2104
|
-
* to all changes in the Store, use the addTablesListener method.
|
|
2105
|
-
*
|
|
2106
2208
|
* The provided listener is a TableIdsListener function, and will be called
|
|
2107
2209
|
* with a reference to the Store.
|
|
2108
2210
|
*
|
|
2211
|
+
* By default, such a listener is only called when a Table is added or
|
|
2212
|
+
* removed. To listen to all changes in the Store, use the addTablesListener
|
|
2213
|
+
* method.
|
|
2214
|
+
*
|
|
2215
|
+
* Since v2.0.0, you can use the optional `trackReorder` parameter to
|
|
2216
|
+
* additionally track when the set of Ids has not changed, but the order has -
|
|
2217
|
+
* for example when a Table from the middle of the Store is removed and then
|
|
2218
|
+
* added back within the same transaction. This behavior is disabled by
|
|
2219
|
+
* default due to the potential performance cost of detecting such changes.
|
|
2220
|
+
*
|
|
2109
2221
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2110
2222
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2111
2223
|
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
@@ -2116,6 +2228,9 @@ export interface Store {
|
|
|
2116
2228
|
*
|
|
2117
2229
|
* @param listener The function that will be called whenever the Table Ids in
|
|
2118
2230
|
* the Store change.
|
|
2231
|
+
* @param trackReorder An optional boolean that indicates that the listener
|
|
2232
|
+
* should be called if the set of Ids remains the same but their order
|
|
2233
|
+
* changes.
|
|
2119
2234
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2120
2235
|
* Store data.
|
|
2121
2236
|
* @returns A unique Id for the listener that can later be used to call it
|
|
@@ -2145,7 +2260,8 @@ export interface Store {
|
|
|
2145
2260
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
2146
2261
|
* const listenerId = store.addTableIdsListener(
|
|
2147
2262
|
* (store) => store.setCell('meta', 'update', 'store', true),
|
|
2148
|
-
*
|
|
2263
|
+
* false, // track reorder
|
|
2264
|
+
* true, // mutator
|
|
2149
2265
|
* );
|
|
2150
2266
|
*
|
|
2151
2267
|
* store.setTable('species', {dog: {price: 5}});
|
|
@@ -2156,21 +2272,25 @@ export interface Store {
|
|
|
2156
2272
|
* ```
|
|
2157
2273
|
* @category Listener
|
|
2158
2274
|
*/
|
|
2159
|
-
addTableIdsListener(
|
|
2275
|
+
addTableIdsListener(
|
|
2276
|
+
listener: TableIdsListener,
|
|
2277
|
+
trackReorder?: boolean,
|
|
2278
|
+
mutator?: boolean,
|
|
2279
|
+
): Id;
|
|
2160
2280
|
|
|
2161
2281
|
/**
|
|
2162
2282
|
* The addTableListener method registers a listener function with the Store
|
|
2163
2283
|
* that will be called whenever data in a Table changes.
|
|
2164
2284
|
*
|
|
2165
|
-
* You can either listen to a single Table (by specifying its Id as the
|
|
2166
|
-
* method's first parameter) or changes to any Table (by providing a `null`
|
|
2167
|
-
* wildcard).
|
|
2168
|
-
*
|
|
2169
2285
|
* The provided listener is a TableListener function, and will be called with
|
|
2170
2286
|
* a reference to the Store, the Id of the Table that changed, and a
|
|
2171
2287
|
* GetCellChange function in case you need to inspect any changes that
|
|
2172
2288
|
* occurred.
|
|
2173
2289
|
*
|
|
2290
|
+
* You can either listen to a single Table (by specifying its Id as the
|
|
2291
|
+
* method's first parameter) or changes to any Table (by providing a `null`
|
|
2292
|
+
* wildcard).
|
|
2293
|
+
*
|
|
2174
2294
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2175
2295
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2176
2296
|
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
@@ -2259,14 +2379,21 @@ export interface Store {
|
|
|
2259
2379
|
* The addRowIdsListener method registers a listener function with the Store
|
|
2260
2380
|
* that will be called whenever the Row Ids in a Table change.
|
|
2261
2381
|
*
|
|
2262
|
-
*
|
|
2263
|
-
*
|
|
2382
|
+
* The provided listener is a RowIdsListener function, and will be called with
|
|
2383
|
+
* a reference to the Store and the Id of the Table that changed.
|
|
2384
|
+
*
|
|
2385
|
+
* By default, such a listener is only called when a Row is added or removed.
|
|
2386
|
+
* To listen to all changes in the Table, use the addTableListener method.
|
|
2264
2387
|
*
|
|
2265
2388
|
* You can either listen to a single Table (by specifying its Id as the
|
|
2266
|
-
* method's first parameter) or changes to any Table (by providing `null`
|
|
2389
|
+
* method's first parameter) or changes to any Table (by providing a `null`
|
|
2390
|
+
* wildcard).
|
|
2267
2391
|
*
|
|
2268
|
-
*
|
|
2269
|
-
*
|
|
2392
|
+
* Since v2.0.0, you can use the optional `trackReorder` parameter to
|
|
2393
|
+
* additionally track when the set of Ids has not changed, but the order has -
|
|
2394
|
+
* for example when a Row from the middle of the Table is removed and then
|
|
2395
|
+
* added back within the same transaction. This behavior is disabled by
|
|
2396
|
+
* default due to the potential performance cost of detecting such changes.
|
|
2270
2397
|
*
|
|
2271
2398
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2272
2399
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
@@ -2279,6 +2406,9 @@ export interface Store {
|
|
|
2279
2406
|
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
2280
2407
|
* @param listener The function that will be called whenever the Row Ids in
|
|
2281
2408
|
* the Table change.
|
|
2409
|
+
* @param trackReorder An optional boolean that indicates that the listener
|
|
2410
|
+
* should be called if the set of Ids remains the same but their order
|
|
2411
|
+
* changes.
|
|
2282
2412
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2283
2413
|
* Store data.
|
|
2284
2414
|
* @returns A unique Id for the listener that can later be used to call it
|
|
@@ -2301,6 +2431,36 @@ export interface Store {
|
|
|
2301
2431
|
* store.delListener(listenerId);
|
|
2302
2432
|
* ```
|
|
2303
2433
|
* @example
|
|
2434
|
+
* This example registers a listener that responds to a change of order in the
|
|
2435
|
+
* rows of a specific Table, even though the set of Ids themselves has not
|
|
2436
|
+
* changed.
|
|
2437
|
+
*
|
|
2438
|
+
* ```js
|
|
2439
|
+
* const store = createStore().setTables({
|
|
2440
|
+
* pets: {
|
|
2441
|
+
* fido: {species: 'dog'},
|
|
2442
|
+
* felix: {species: 'cat'},
|
|
2443
|
+
* },
|
|
2444
|
+
* });
|
|
2445
|
+
* const listenerId = store.addRowIdsListener(
|
|
2446
|
+
* 'pets',
|
|
2447
|
+
* (store) => {
|
|
2448
|
+
* console.log('Row Ids or order for pets table changed');
|
|
2449
|
+
* console.log(store.getRowIds('pets'));
|
|
2450
|
+
* },
|
|
2451
|
+
* true, // track reorder
|
|
2452
|
+
* );
|
|
2453
|
+
*
|
|
2454
|
+
* store.transaction(() => {
|
|
2455
|
+
* store.delRow('pets', 'fido');
|
|
2456
|
+
* store.setRow('pets', 'fido', {species: 'dog'});
|
|
2457
|
+
* });
|
|
2458
|
+
* // -> 'Row Ids or order for pets table changed'
|
|
2459
|
+
* // -> ['felix', 'fido']
|
|
2460
|
+
*
|
|
2461
|
+
* store.delListener(listenerId);
|
|
2462
|
+
* ```
|
|
2463
|
+
* @example
|
|
2304
2464
|
* This example registers a listener that responds to any change to the Row
|
|
2305
2465
|
* Ids of any Table.
|
|
2306
2466
|
*
|
|
@@ -2329,7 +2489,8 @@ export interface Store {
|
|
|
2329
2489
|
* const listenerId = store.addRowIdsListener(
|
|
2330
2490
|
* 'pets',
|
|
2331
2491
|
* (store, tableId) => store.setCell('meta', 'update', tableId, true),
|
|
2332
|
-
*
|
|
2492
|
+
* false, // track reorder
|
|
2493
|
+
* true, // mutator
|
|
2333
2494
|
* );
|
|
2334
2495
|
*
|
|
2335
2496
|
* store.setRow('pets', 'felix', {species: 'cat'});
|
|
@@ -2343,6 +2504,175 @@ export interface Store {
|
|
|
2343
2504
|
addRowIdsListener(
|
|
2344
2505
|
tableId: IdOrNull,
|
|
2345
2506
|
listener: RowIdsListener,
|
|
2507
|
+
trackReorder?: boolean,
|
|
2508
|
+
mutator?: boolean,
|
|
2509
|
+
): Id;
|
|
2510
|
+
|
|
2511
|
+
/**
|
|
2512
|
+
* The addSortedRowIdsListener method registers a listener function with the
|
|
2513
|
+
* Store that will be called whenever sorted Row Ids in a Table change.
|
|
2514
|
+
*
|
|
2515
|
+
* The provided listener is a SortedRowIdsListener function, and will be
|
|
2516
|
+
* called with a reference to the Store, the Id of the Table whose Row Ids
|
|
2517
|
+
* sorting changed, the Cell Id being used to sort them, and whether
|
|
2518
|
+
* descending or not. It also receives the sorted array of Ids itself, so that
|
|
2519
|
+
* you can use them in the listener without the additional cost of an explicit
|
|
2520
|
+
* call to getSortedRowIds.
|
|
2521
|
+
*
|
|
2522
|
+
* Such a listener is called when a Row is added or removed, but also when a
|
|
2523
|
+
* value in the specified Cell (somewhere in the Table) has changed enough to
|
|
2524
|
+
* change the sorting of the Row Ids.
|
|
2525
|
+
*
|
|
2526
|
+
* Unlike most other listeners, you cannot provide wildcards (due to the cost
|
|
2527
|
+
* of detecting changes to the sorting). You can only listen to a single
|
|
2528
|
+
* specified Table, sorted by a single specified Cell.
|
|
2529
|
+
*
|
|
2530
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
2531
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2532
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
2533
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
2534
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
2535
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
2536
|
+
* though they will fire non-mutator listeners.
|
|
2537
|
+
*
|
|
2538
|
+
* @param tableId The Id of the Table to listen to.
|
|
2539
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2540
|
+
* `undefined` to by sort the Row Id itself.
|
|
2541
|
+
* @param descending Whether the sorting should be in descending order.
|
|
2542
|
+
* @param listener The function that will be called whenever the sorted Row
|
|
2543
|
+
* Ids in the Table change.
|
|
2544
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2545
|
+
* Store data.
|
|
2546
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
2547
|
+
* explicitly, or to remove it.
|
|
2548
|
+
* @example
|
|
2549
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2550
|
+
* Row Ids of a specific Table.
|
|
2551
|
+
*
|
|
2552
|
+
* ```js
|
|
2553
|
+
* const store = createStore().setTables({
|
|
2554
|
+
* pets: {
|
|
2555
|
+
* cujo: {species: 'wolf'},
|
|
2556
|
+
* felix: {species: 'cat'},
|
|
2557
|
+
* },
|
|
2558
|
+
* });
|
|
2559
|
+
* console.log(store.getSortedRowIds('pets', 'species', false));
|
|
2560
|
+
* // -> ['felix', 'cujo']
|
|
2561
|
+
*
|
|
2562
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
2563
|
+
* 'pets',
|
|
2564
|
+
* 'species',
|
|
2565
|
+
* false,
|
|
2566
|
+
* (store, tableId, cellId, descending, sortedRowIds) => {
|
|
2567
|
+
* console.log(`Sorted Row Ids for ${tableId} table changed`);
|
|
2568
|
+
* console.log(sortedRowIds);
|
|
2569
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
2570
|
+
* },
|
|
2571
|
+
* );
|
|
2572
|
+
*
|
|
2573
|
+
* store.setRow('pets', 'fido', {species: 'dog'});
|
|
2574
|
+
* // -> 'Sorted Row Ids for pets table changed'
|
|
2575
|
+
* // -> ['felix', 'fido', 'cujo']
|
|
2576
|
+
*
|
|
2577
|
+
* store.delListener(listenerId);
|
|
2578
|
+
* ```
|
|
2579
|
+
* @example
|
|
2580
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2581
|
+
* Row Ids of a specific Table. The Row Ids are sorted by their own value,
|
|
2582
|
+
* since the `cellId` parameter is explicitly undefined.
|
|
2583
|
+
*
|
|
2584
|
+
* ```js
|
|
2585
|
+
* const store = createStore().setTables({
|
|
2586
|
+
* pets: {
|
|
2587
|
+
* fido: {species: 'dog'},
|
|
2588
|
+
* felix: {species: 'cat'},
|
|
2589
|
+
* },
|
|
2590
|
+
* });
|
|
2591
|
+
* console.log(store.getSortedRowIds('pets', undefined, false));
|
|
2592
|
+
* // -> ['felix', 'fido']
|
|
2593
|
+
*
|
|
2594
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
2595
|
+
* 'pets',
|
|
2596
|
+
* undefined,
|
|
2597
|
+
* false,
|
|
2598
|
+
* (store, tableId, cellId, descending, sortedRowIds) => {
|
|
2599
|
+
* console.log(`Sorted Row Ids for ${tableId} table changed`);
|
|
2600
|
+
* console.log(sortedRowIds);
|
|
2601
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
2602
|
+
* },
|
|
2603
|
+
* );
|
|
2604
|
+
*
|
|
2605
|
+
* store.setRow('pets', 'cujo', {species: 'wolf'});
|
|
2606
|
+
* // -> 'Sorted Row Ids for pets table changed'
|
|
2607
|
+
* // -> ['cujo', 'felix', 'fido']
|
|
2608
|
+
*
|
|
2609
|
+
* store.delListener(listenerId);
|
|
2610
|
+
* ```
|
|
2611
|
+
* @example
|
|
2612
|
+
* This example registers a listener that responds to a change in the sorting
|
|
2613
|
+
* of the rows of a specific Table, even though the set of Ids themselves has
|
|
2614
|
+
* not changed.
|
|
2615
|
+
*
|
|
2616
|
+
* ```js
|
|
2617
|
+
* const store = createStore().setTables({
|
|
2618
|
+
* pets: {
|
|
2619
|
+
* fido: {species: 'dog'},
|
|
2620
|
+
* felix: {species: 'cat'},
|
|
2621
|
+
* },
|
|
2622
|
+
* });
|
|
2623
|
+
* console.log(store.getSortedRowIds('pets', 'species', false));
|
|
2624
|
+
* // -> ['felix', 'fido']
|
|
2625
|
+
*
|
|
2626
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
2627
|
+
* 'pets',
|
|
2628
|
+
* 'species',
|
|
2629
|
+
* false,
|
|
2630
|
+
* (store, tableId, cellId, descending, sortedRowIds) => {
|
|
2631
|
+
* console.log(`Sorted Row Ids for ${tableId} table changed`);
|
|
2632
|
+
* console.log(sortedRowIds);
|
|
2633
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
2634
|
+
* },
|
|
2635
|
+
* );
|
|
2636
|
+
*
|
|
2637
|
+
* store.setCell('pets', 'felix', 'species', 'tiger');
|
|
2638
|
+
* // -> 'Sorted Row Ids for pets table changed'
|
|
2639
|
+
* // -> ['fido', 'felix']
|
|
2640
|
+
*
|
|
2641
|
+
* store.delListener(listenerId);
|
|
2642
|
+
* ```
|
|
2643
|
+
* @example
|
|
2644
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2645
|
+
* Row Ids of a specific Table, and which also mutates the Store itself.
|
|
2646
|
+
*
|
|
2647
|
+
* ```js
|
|
2648
|
+
* const store = createStore().setTables({
|
|
2649
|
+
* pets: {
|
|
2650
|
+
* cujo: {species: 'wolf'},
|
|
2651
|
+
* felix: {species: 'cat'},
|
|
2652
|
+
* },
|
|
2653
|
+
* });
|
|
2654
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
2655
|
+
* 'pets',
|
|
2656
|
+
* 'species',
|
|
2657
|
+
* false,
|
|
2658
|
+
* (store, tableId) => store.setCell('meta', 'sorted', tableId, true),
|
|
2659
|
+
* true, // mutator
|
|
2660
|
+
* );
|
|
2661
|
+
*
|
|
2662
|
+
* store.setRow('pets', 'fido', {species: 'dog'});
|
|
2663
|
+
* console.log(store.getTable('meta'));
|
|
2664
|
+
* // -> {sorted: {pets: true}}
|
|
2665
|
+
*
|
|
2666
|
+
* store.delListener(listenerId);
|
|
2667
|
+
* ```
|
|
2668
|
+
* @category Listener
|
|
2669
|
+
* @since v2.0.0
|
|
2670
|
+
*/
|
|
2671
|
+
addSortedRowIdsListener(
|
|
2672
|
+
tableId: Id,
|
|
2673
|
+
cellId: Id | undefined,
|
|
2674
|
+
descending: boolean,
|
|
2675
|
+
listener: SortedRowIdsListener,
|
|
2346
2676
|
mutator?: boolean,
|
|
2347
2677
|
): Id;
|
|
2348
2678
|
|
|
@@ -2350,6 +2680,11 @@ export interface Store {
|
|
|
2350
2680
|
* The addRowListener method registers a listener function with the Store that
|
|
2351
2681
|
* will be called whenever data in a Row changes.
|
|
2352
2682
|
*
|
|
2683
|
+
* The provided listener is a RowListener function, and will be called with a
|
|
2684
|
+
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
2685
|
+
* that changed, and a GetCellChange function in case you need to inspect any
|
|
2686
|
+
* changes that occurred.
|
|
2687
|
+
*
|
|
2353
2688
|
* You can either listen to a single Row (by specifying the Table Id and Row
|
|
2354
2689
|
* Id as the method's first two parameters) or changes to any Row (by
|
|
2355
2690
|
* providing `null` wildcards).
|
|
@@ -2359,11 +2694,6 @@ export interface Store {
|
|
|
2359
2694
|
* Table, any Row in a specific Table, a specific Row in any Table, or any Row
|
|
2360
2695
|
* in any Table.
|
|
2361
2696
|
*
|
|
2362
|
-
* The provided listener is a RowListener function, and will be called with a
|
|
2363
|
-
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
2364
|
-
* that changed, and a GetCellChange function in case you need to inspect any
|
|
2365
|
-
* changes that occurred.
|
|
2366
|
-
*
|
|
2367
2697
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2368
2698
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2369
2699
|
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
@@ -2460,21 +2790,27 @@ export interface Store {
|
|
|
2460
2790
|
* The addCellIdsListener method registers a listener function with the Store
|
|
2461
2791
|
* that will be called whenever the Cell Ids in a Row change.
|
|
2462
2792
|
*
|
|
2463
|
-
*
|
|
2464
|
-
* to
|
|
2793
|
+
* The provided listener is a CellIdsListener function, and will be called
|
|
2794
|
+
* with a reference to the Store, the Id of the Table, and the Id of the Row
|
|
2795
|
+
* that changed.
|
|
2796
|
+
*
|
|
2797
|
+
* By default, such a listener is only called when a Cell is added or removed.
|
|
2798
|
+
* To listen to all changes in the Row, use the addRowListener method.
|
|
2465
2799
|
*
|
|
2466
2800
|
* You can either listen to a single Row (by specifying the Table Id and Row
|
|
2467
2801
|
* Id as the method's first two parameters) or changes to any Row (by
|
|
2468
|
-
* providing `null`).
|
|
2802
|
+
* providing a `null` wildcard).
|
|
2469
2803
|
*
|
|
2470
2804
|
* Both, either, or neither of the `tableId` and `rowId` parameters can be
|
|
2471
2805
|
* wildcarded with `null`. You can listen to a specific Row in a specific
|
|
2472
2806
|
* Table, any Row in a specific Table, a specific Row in any Table, or any Row
|
|
2473
2807
|
* in any Table.
|
|
2474
2808
|
*
|
|
2475
|
-
*
|
|
2476
|
-
*
|
|
2477
|
-
*
|
|
2809
|
+
* Since v2.0.0, you can use the optional `trackReorder` parameter to
|
|
2810
|
+
* additionally track when the set of Ids has not changed, but the order has -
|
|
2811
|
+
* for example when a Cell from the middle of the Row is removed and then
|
|
2812
|
+
* added back within the same transaction. This behavior is disabled by
|
|
2813
|
+
* default due to the potential performance cost of detecting such changes.
|
|
2478
2814
|
*
|
|
2479
2815
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2480
2816
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
@@ -2488,6 +2824,9 @@ export interface Store {
|
|
|
2488
2824
|
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
2489
2825
|
* @param listener The function that will be called whenever the Cell Ids in
|
|
2490
2826
|
* the Row change.
|
|
2827
|
+
* @param trackReorder An optional boolean that indicates that the listener
|
|
2828
|
+
* should be called if the set of Ids remains the same but their order
|
|
2829
|
+
* changes.
|
|
2491
2830
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2492
2831
|
* Store data.
|
|
2493
2832
|
* @returns A unique Id for the listener that can later be used to call it
|
|
@@ -2544,7 +2883,8 @@ export interface Store {
|
|
|
2544
2883
|
* 'fido',
|
|
2545
2884
|
* (store, tableId, rowId) =>
|
|
2546
2885
|
* store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
|
|
2547
|
-
*
|
|
2886
|
+
* false, // track reorder
|
|
2887
|
+
* true, // mutator
|
|
2548
2888
|
* );
|
|
2549
2889
|
*
|
|
2550
2890
|
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
@@ -2559,6 +2899,7 @@ export interface Store {
|
|
|
2559
2899
|
tableId: IdOrNull,
|
|
2560
2900
|
rowId: IdOrNull,
|
|
2561
2901
|
listener: CellIdsListener,
|
|
2902
|
+
trackReorder?: boolean,
|
|
2562
2903
|
mutator?: boolean,
|
|
2563
2904
|
): Id;
|
|
2564
2905
|
|
|
@@ -2566,6 +2907,12 @@ export interface Store {
|
|
|
2566
2907
|
* The addCellListener method registers a listener function with the Store
|
|
2567
2908
|
* that will be called whenever data in a Cell changes.
|
|
2568
2909
|
*
|
|
2910
|
+
* The provided listener is a CellListener function, and will be called with a
|
|
2911
|
+
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
2912
|
+
* that changed, the Id of the Cell that changed, the new Cell value, the old
|
|
2913
|
+
* Cell value, and a GetCellChange function in case you need to inspect any
|
|
2914
|
+
* changes that occurred.
|
|
2915
|
+
*
|
|
2569
2916
|
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
2570
2917
|
* and Cell Id as the method's first three parameters) or changes to any Cell
|
|
2571
2918
|
* (by providing `null` wildcards).
|
|
@@ -2575,12 +2922,6 @@ export interface Store {
|
|
|
2575
2922
|
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
2576
2923
|
* every other combination of wildcards.
|
|
2577
2924
|
*
|
|
2578
|
-
* The provided listener is a CellListener function, and will be called with a
|
|
2579
|
-
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
2580
|
-
* that changed, the Id of the Cell that changed, the new Cell value, the old
|
|
2581
|
-
* Cell value, and a GetCellChange function in case you need to inspect any
|
|
2582
|
-
* changes that occurred.
|
|
2583
|
-
*
|
|
2584
2925
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2585
2926
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2586
2927
|
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
@@ -2687,6 +3028,14 @@ export interface Store {
|
|
|
2687
3028
|
* Store that will be called whenever invalid data was attempted to be written
|
|
2688
3029
|
* to a Cell.
|
|
2689
3030
|
*
|
|
3031
|
+
* The provided listener is an InvalidCellListener function, and will be
|
|
3032
|
+
* called with a reference to the Store, the Id of the Table, the Id of the
|
|
3033
|
+
* Row, and the Id of Cell that were being attempted to be changed. It is also
|
|
3034
|
+
* given the invalid value of the Cell, which could have been of absolutely
|
|
3035
|
+
* any type. Since there could have been multiple failed attempts to set the
|
|
3036
|
+
* Cell within a single transaction, this is an array containing each attempt,
|
|
3037
|
+
* chronologically.
|
|
3038
|
+
*
|
|
2690
3039
|
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
2691
3040
|
* and Cell Id as the method's first three parameters) or invalid attempts to
|
|
2692
3041
|
* change any Cell (by providing `null` wildcards).
|
|
@@ -2696,14 +3045,6 @@ export interface Store {
|
|
|
2696
3045
|
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
2697
3046
|
* every other combination of wildcards.
|
|
2698
3047
|
*
|
|
2699
|
-
* The provided listener is an InvalidCellListener function, and will be
|
|
2700
|
-
* called with a reference to the Store, the Id of the Table, the Id of the
|
|
2701
|
-
* Row, and the Id of Cell that were being attempted to be changed. It is also
|
|
2702
|
-
* given the invalid value of the Cell, which could have been of absolutely
|
|
2703
|
-
* any type. Since there could have been multiple failed attempts to set the
|
|
2704
|
-
* Cell within a single transaction, this is an array containing each attempt,
|
|
2705
|
-
* chronologically.
|
|
2706
|
-
*
|
|
2707
3048
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2708
3049
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2709
3050
|
* mutations will be silently ignored. All relevant mutator listeners (with
|