tinybase 2.0.0-beta.0 → 2.0.0-beta.3

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.
Files changed (63) hide show
  1. package/lib/checkpoints.d.ts +4 -3
  2. package/lib/checkpoints.js +1 -1
  3. package/lib/checkpoints.js.gz +0 -0
  4. package/lib/common.js +1 -1
  5. package/lib/common.js.gz +0 -0
  6. package/lib/debug/checkpoints.d.ts +4 -3
  7. package/lib/debug/checkpoints.js +13 -16
  8. package/lib/debug/common.js +4 -1
  9. package/lib/debug/indexes.d.ts +4 -2
  10. package/lib/debug/indexes.js +13 -15
  11. package/lib/debug/metrics.d.ts +1 -1
  12. package/lib/debug/metrics.js +13 -16
  13. package/lib/debug/persisters.d.ts +6 -0
  14. package/lib/debug/queries.d.ts +249 -299
  15. package/lib/debug/queries.js +67 -192
  16. package/lib/debug/relationships.d.ts +6 -5
  17. package/lib/debug/relationships.js +13 -16
  18. package/lib/debug/store.d.ts +386 -86
  19. package/lib/debug/store.js +278 -216
  20. package/lib/debug/tinybase.js +318 -390
  21. package/lib/debug/ui-react.d.ts +4320 -1796
  22. package/lib/debug/ui-react.js +380 -98
  23. package/lib/indexes.d.ts +4 -2
  24. package/lib/indexes.js +1 -1
  25. package/lib/indexes.js.gz +0 -0
  26. package/lib/metrics.d.ts +1 -1
  27. package/lib/metrics.js +1 -1
  28. package/lib/metrics.js.gz +0 -0
  29. package/lib/persisters.d.ts +6 -0
  30. package/lib/queries.d.ts +249 -299
  31. package/lib/queries.js +1 -1
  32. package/lib/queries.js.gz +0 -0
  33. package/lib/relationships.d.ts +6 -5
  34. package/lib/relationships.js +1 -1
  35. package/lib/relationships.js.gz +0 -0
  36. package/lib/store.d.ts +386 -86
  37. package/lib/store.js +1 -1
  38. package/lib/store.js.gz +0 -0
  39. package/lib/tinybase.js +1 -1
  40. package/lib/tinybase.js.gz +0 -0
  41. package/lib/ui-react.d.ts +4320 -1796
  42. package/lib/ui-react.js +1 -1
  43. package/lib/ui-react.js.gz +0 -0
  44. package/lib/umd/checkpoints.js +1 -1
  45. package/lib/umd/checkpoints.js.gz +0 -0
  46. package/lib/umd/common.js +1 -1
  47. package/lib/umd/common.js.gz +0 -0
  48. package/lib/umd/indexes.js +1 -1
  49. package/lib/umd/indexes.js.gz +0 -0
  50. package/lib/umd/metrics.js +1 -1
  51. package/lib/umd/metrics.js.gz +0 -0
  52. package/lib/umd/queries.js +1 -1
  53. package/lib/umd/queries.js.gz +0 -0
  54. package/lib/umd/relationships.js +1 -1
  55. package/lib/umd/relationships.js.gz +0 -0
  56. package/lib/umd/store.js +1 -1
  57. package/lib/umd/store.js.gz +0 -0
  58. package/lib/umd/tinybase.js +1 -1
  59. package/lib/umd/tinybase.js.gz +0 -0
  60. package/lib/umd/ui-react.js +1 -1
  61. package/lib/umd/ui-react.js.gz +0 -0
  62. package/package.json +26 -26
  63. 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
- * the Cell value has since been added.
97
+ * the Cell value has since been added.
98
98
  *
99
99
  * @category Store
100
100
  */
@@ -284,6 +284,40 @@ 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, whether descending or not, and the offset and limit of the number of
297
+ * Ids returned, for pagination purposes. It also receives the sorted array of
298
+ * Ids itself, so that you can use them in the listener without the additional
299
+ * cost of an explicit call to getSortedRowIds.
300
+ *
301
+ * @param store A reference to the Store that changed.
302
+ * @param tableId The Id of the Table whose sorted Row Ids changed.
303
+ * @param cellId The Id of the Cell whose values were used for the sorting.
304
+ * @param descending Whether the sorting was in descending order.
305
+ * @param offset The number of Row Ids skipped.
306
+ * @param limit The maximum number of Row Ids returned.
307
+ * @param sortedRowIds The sorted Row Ids themselves.
308
+ * @category Listener
309
+ * @since v2.0.0
310
+ */
311
+ export type SortedRowIdsListener = (
312
+ store: Store,
313
+ tableId: Id,
314
+ cellId: Id | undefined,
315
+ descending: boolean,
316
+ offset: number,
317
+ limit: number | undefined,
318
+ sortedRowIds: Ids,
319
+ ) => void;
320
+
287
321
  /**
288
322
  * The RowListener type describes a function that is used to listen to changes
289
323
  * to a Row.
@@ -567,39 +601,43 @@ export type InvalidCells = {
567
601
  */
568
602
  export type StoreListenerStats = {
569
603
  /**
570
- * The number of TablesListeners registered with the Store.
604
+ * The number of TablesListener functions registered with the Store.
571
605
  */
572
606
  tables?: number;
573
607
  /**
574
- * The number of TableIdsListeners registered with the Store.
608
+ * The number of TableIdsListener functions registered with the Store.
575
609
  */
576
610
  tableIds?: number;
577
611
  /**
578
- * The number of TableListeners registered with the Store.
612
+ * The number of TableListener functions registered with the Store.
579
613
  */
580
614
  table?: number;
581
615
  /**
582
- * The number of RowIdsListeners registered with the Store.
616
+ * The number of RowIdsListener functions registered with the Store.
583
617
  */
584
618
  rowIds?: number;
585
619
  /**
586
- * The number of RowListeners registered with the Store.
620
+ * The number of SortedRowIdsListener functions registered with the Store.
621
+ */
622
+ sortedRowIds?: number;
623
+ /**
624
+ * The number of RowListener functions registered with the Store.
587
625
  */
588
626
  row?: number;
589
627
  /**
590
- * The number of CellIdsListeners registered with the Store.
628
+ * The number of CellIdsListener functions registered with the Store.
591
629
  */
592
630
  cellIds?: number;
593
631
  /**
594
- * The number of CellListeners registered with the Store.
632
+ * The number of CellListener functions registered with the Store.
595
633
  */
596
634
  cell?: number;
597
635
  /**
598
- * The number of InvalidCellListeners registered with the Store.
636
+ * The number of InvalidCellListener functions registered with the Store.
599
637
  */
600
638
  invalidCell?: number;
601
639
  /**
602
- * The number of TransactionListeners registered with the Store.
640
+ * The number of TransactionListener functions registered with the Store.
603
641
  */
604
642
  transaction?: number;
605
643
  };
@@ -666,6 +704,7 @@ export type StoreListenerStats = {
666
704
  * |Table Ids|getTableIds|-|-|addTableIdsListener|
667
705
  * |Table|getTable|setTable|delTable|addTableListener|
668
706
  * |Row Ids|getRowIds|-|-|addRowIdsListener|
707
+ * |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
669
708
  * |Row|getRow|setRow|delRow|addRowListener|
670
709
  * |Cell Ids|getCellIds|-|-|addCellIdsListener|
671
710
  * |Cell|getCell|setCell|delCell|addCellListener|
@@ -793,9 +832,7 @@ export interface Store {
793
832
  * The getTableIds method returns the Ids of every Table in the Store.
794
833
  *
795
834
  * Note that this returns a copy of, rather than a reference, to the list of
796
- * Ids, so changes made to the list are not made to the Store itself. Since
797
- * v2.0.0, the order is significant: this method will return the Ids in the
798
- * order in which each Table was added.
835
+ * Ids, so changes made to the list are not made to the Store itself.
799
836
  *
800
837
  * @returns An array of the Ids of every Table in the Store.
801
838
  * @example
@@ -860,9 +897,7 @@ export interface Store {
860
897
  * The getRowIds method returns the Ids of every Row in a given Table.
861
898
  *
862
899
  * Note that this returns a copy of, rather than a reference, to the list of
863
- * Ids, so changes made to the list are not made to the Store itself. Since
864
- * v2.0.0, the order is significant: this method will return the Ids in the
865
- * order in which each Row was added.
900
+ * Ids, so changes made to the list are not made to the Store itself.
866
901
  *
867
902
  * @param tableId The Id of the Table in the Store.
868
903
  * @returns An array of the Ids of every Row in the Table.
@@ -892,6 +927,113 @@ export interface Store {
892
927
  */
893
928
  getRowIds(tableId: Id): Ids;
894
929
 
930
+ /**
931
+ * The getSortedRowIds method returns the Ids of every Row in a given Table,
932
+ * sorted according to the values in a specified Cell.
933
+ *
934
+ * The sorting of the rows is alphanumeric, and you can indicate whether it
935
+ * should be in descending order. The `offset` and `limit` parameters are used
936
+ * to paginate results, but default to `0` and `undefined` to return all
937
+ * available Row Ids if not specified.
938
+ *
939
+ * Note that every call to this method will perform the sorting afresh - there
940
+ * is no caching of the results - and so you are advised to memoize the
941
+ * results yourself, especially when the Table is large. For a performant
942
+ * approach to tracking the sorted Row Ids when they change, use the
943
+ * addSortedRowIdsListener method.
944
+ *
945
+ * If the Table does not exist, an empty array is returned.
946
+ *
947
+ * @param tableId The Id of the Table in the Store.
948
+ * @param cellId The Id of the Cell whose values are used for the sorting, or
949
+ * `undefined` to by sort the Row Id itself.
950
+ * @param descending Whether the sorting should be in descending order.
951
+ * @param offset The number of Row Ids to skip for pagination purposes, if
952
+ * any.
953
+ * @param limit The maximum number of Row Ids to return, or `undefined` for
954
+ * all.
955
+ * @returns An array of the sorted Ids of every Row in the Table.
956
+ * @example
957
+ * This example retrieves sorted Row Ids in a Table.
958
+ *
959
+ * ```js
960
+ * const store = createStore().setTables({
961
+ * pets: {
962
+ * fido: {species: 'dog'},
963
+ * felix: {species: 'cat'},
964
+ * },
965
+ * });
966
+ * console.log(store.getSortedRowIds('pets', 'species'));
967
+ * // -> ['felix', 'fido']
968
+ * ```
969
+ * @example
970
+ * This example retrieves sorted Row Ids in a Table in reverse order.
971
+ *
972
+ * ```js
973
+ * const store = createStore().setTables({
974
+ * pets: {
975
+ * fido: {species: 'dog'},
976
+ * felix: {species: 'cat'},
977
+ * cujo: {species: 'wolf'},
978
+ * },
979
+ * });
980
+ * console.log(store.getSortedRowIds('pets', 'species', true));
981
+ * // -> ['cujo', 'fido', 'felix']
982
+ * ```
983
+ * @example
984
+ * This example retrieves two pages of Row Ids in a Table.
985
+ *
986
+ * ```js
987
+ * const store = createStore().setTables({
988
+ * pets: {
989
+ * fido: {price: 6},
990
+ * felix: {price: 5},
991
+ * mickey: {price: 2},
992
+ * tom: {price: 4},
993
+ * carnaby: {price: 3},
994
+ * lowly: {price: 1},
995
+ * },
996
+ * });
997
+ * console.log(store.getSortedRowIds('pets', 'price', false, 0, 2));
998
+ * // -> ['lowly', 'mickey']
999
+ * console.log(store.getSortedRowIds('pets', 'price', false, 2, 2));
1000
+ * // -> ['carnaby', 'tom']
1001
+ * ```
1002
+ * @example
1003
+ * This example retrieves Row Ids sorted by their own value, since the
1004
+ * `cellId` parameter is undefined.
1005
+ *
1006
+ * ```js
1007
+ * const store = createStore().setTables({
1008
+ * pets: {
1009
+ * fido: {species: 'dog'},
1010
+ * felix: {species: 'cat'},
1011
+ * cujo: {species: 'wolf'},
1012
+ * },
1013
+ * });
1014
+ * console.log(store.getSortedRowIds('pets'));
1015
+ * // -> ['cujo', 'felix', 'fido']
1016
+ * ```
1017
+ * @example
1018
+ * This example retrieves the sorted Row Ids of a Table that does not exist,
1019
+ * returning an empty array.
1020
+ *
1021
+ * ```js
1022
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1023
+ * console.log(store.getSortedRowIds('employees'));
1024
+ * // -> []
1025
+ * ```
1026
+ * @category Getter
1027
+ * @since v2.0.0
1028
+ */
1029
+ getSortedRowIds(
1030
+ tableId: Id,
1031
+ cellId?: Id,
1032
+ descending?: boolean,
1033
+ offset?: number,
1034
+ limit?: number,
1035
+ ): Ids;
1036
+
895
1037
  /**
896
1038
  * The getRow method returns an object containing the entire data of a single
897
1039
  * Row in a given Table.
@@ -934,9 +1076,7 @@ export interface Store {
934
1076
  * given Table.
935
1077
  *
936
1078
  * Note that this returns a copy of, rather than a reference, to the list of
937
- * Ids, so changes made to the list are not made to the Store itself. Since
938
- * v2.0.0, the order is significant: this method will return the Ids in the
939
- * order in which each Cell was added.
1079
+ * Ids, so changes made to the list are not made to the Store itself.
940
1080
  *
941
1081
  * @param tableId The Id of the Table in the Store.
942
1082
  * @param rowId The Id of the Row in the Table.
@@ -2102,12 +2242,6 @@ export interface Store {
2102
2242
  * removed. To listen to all changes in the Store, use the addTablesListener
2103
2243
  * method.
2104
2244
  *
2105
- * Since v2.0.0, you can use the optional `trackReorder` parameter to
2106
- * additionally track when the set of Ids has not changed, but the order has -
2107
- * for example when a Table from the middle of the Store is removed and then
2108
- * added back within the same transaction. This behavior is disabled by
2109
- * default due to the potential performance cost of detecting such changes.
2110
- *
2111
2245
  * Use the optional mutator parameter to indicate that there is code in the
2112
2246
  * listener that will mutate Store data. If set to `false` (or omitted), such
2113
2247
  * mutations will be silently ignored. All relevant mutator listeners (with
@@ -2118,9 +2252,6 @@ export interface Store {
2118
2252
  *
2119
2253
  * @param listener The function that will be called whenever the Table Ids in
2120
2254
  * the Store change.
2121
- * @param trackReorder An optional boolean that indicates that the listener
2122
- * should be called if the set of Ids remains the same but their order
2123
- * changes.
2124
2255
  * @param mutator An optional boolean that indicates that the listener mutates
2125
2256
  * Store data.
2126
2257
  * @returns A unique Id for the listener that can later be used to call it
@@ -2150,7 +2281,6 @@ export interface Store {
2150
2281
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2151
2282
  * const listenerId = store.addTableIdsListener(
2152
2283
  * (store) => store.setCell('meta', 'update', 'store', true),
2153
- * false, // track reorder
2154
2284
  * true, // mutator
2155
2285
  * );
2156
2286
  *
@@ -2162,11 +2292,7 @@ export interface Store {
2162
2292
  * ```
2163
2293
  * @category Listener
2164
2294
  */
2165
- addTableIdsListener(
2166
- listener: TableIdsListener,
2167
- trackReorder?: boolean,
2168
- mutator?: boolean,
2169
- ): Id;
2295
+ addTableIdsListener(listener: TableIdsListener, mutator?: boolean): Id;
2170
2296
 
2171
2297
  /**
2172
2298
  * The addTableListener method registers a listener function with the Store
@@ -2279,12 +2405,6 @@ export interface Store {
2279
2405
  * method's first parameter) or changes to any Table (by providing a `null`
2280
2406
  * wildcard).
2281
2407
  *
2282
- * Since v2.0.0, you can use the optional `trackReorder` parameter to
2283
- * additionally track when the set of Ids has not changed, but the order has -
2284
- * for example when a Row from the middle of the Table is removed and then
2285
- * added back within the same transaction. This behavior is disabled by
2286
- * default due to the potential performance cost of detecting such changes.
2287
- *
2288
2408
  * Use the optional mutator parameter to indicate that there is code in the
2289
2409
  * listener that will mutate Store data. If set to `false` (or omitted), such
2290
2410
  * mutations will be silently ignored. All relevant mutator listeners (with
@@ -2296,9 +2416,6 @@ export interface Store {
2296
2416
  * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2297
2417
  * @param listener The function that will be called whenever the Row Ids in
2298
2418
  * the Table change.
2299
- * @param trackReorder An optional boolean that indicates that the listener
2300
- * should be called if the set of Ids remains the same but their order
2301
- * changes.
2302
2419
  * @param mutator An optional boolean that indicates that the listener mutates
2303
2420
  * Store data.
2304
2421
  * @returns A unique Id for the listener that can later be used to call it
@@ -2321,36 +2438,6 @@ export interface Store {
2321
2438
  * store.delListener(listenerId);
2322
2439
  * ```
2323
2440
  * @example
2324
- * This example registers a listener that responds to a change of order in the
2325
- * rows of a specific Table, even though the set of Ids themselves has not
2326
- * changed.
2327
- *
2328
- * ```js
2329
- * const store = createStore().setTables({
2330
- * pets: {
2331
- * fido: {species: 'dog'},
2332
- * felix: {species: 'cat'},
2333
- * },
2334
- * });
2335
- * const listenerId = store.addRowIdsListener(
2336
- * 'pets',
2337
- * (store) => {
2338
- * console.log('Row Ids or order for pets table changed');
2339
- * console.log(store.getRowIds('pets'));
2340
- * },
2341
- * true, // track reorder
2342
- * );
2343
- *
2344
- * store.transaction(() => {
2345
- * store.delRow('pets', 'fido');
2346
- * store.setRow('pets', 'fido', {species: 'dog'});
2347
- * });
2348
- * // -> 'Row Ids or order for pets table changed'
2349
- * // -> ['felix', 'fido']
2350
- *
2351
- * store.delListener(listenerId);
2352
- * ```
2353
- * @example
2354
2441
  * This example registers a listener that responds to any change to the Row
2355
2442
  * Ids of any Table.
2356
2443
  *
@@ -2379,7 +2466,6 @@ export interface Store {
2379
2466
  * const listenerId = store.addRowIdsListener(
2380
2467
  * 'pets',
2381
2468
  * (store, tableId) => store.setCell('meta', 'update', tableId, true),
2382
- * false, // track reorder
2383
2469
  * true, // mutator
2384
2470
  * );
2385
2471
  *
@@ -2394,7 +2480,232 @@ export interface Store {
2394
2480
  addRowIdsListener(
2395
2481
  tableId: IdOrNull,
2396
2482
  listener: RowIdsListener,
2397
- trackReorder?: boolean,
2483
+ mutator?: boolean,
2484
+ ): Id;
2485
+
2486
+ /**
2487
+ * The addSortedRowIdsListener method registers a listener function with the
2488
+ * Store that will be called whenever sorted (and optionally, paginated) Row
2489
+ * Ids in a Table change.
2490
+ *
2491
+ * The provided listener is a SortedRowIdsListener function, and will be
2492
+ * called with a reference to the Store, the Id of the Table whose Row Ids
2493
+ * sorting changed, the Cell Id being used to sort them, whether descending or
2494
+ * not, and the offset and limit of the number of Ids returned, for pagination
2495
+ * purposes. It also receives the sorted array of Ids itself, so that you can
2496
+ * use them in the listener without the additional cost of an explicit call to
2497
+ * getSortedRowIds.
2498
+ *
2499
+ * Such a listener is called when a Row is added or removed, but also when a
2500
+ * value in the specified Cell (somewhere in the Table) has changed enough to
2501
+ * change the sorting of the Row Ids.
2502
+ *
2503
+ * Unlike most other listeners, you cannot provide wildcards (due to the cost
2504
+ * of detecting changes to the sorting). You can only listen to a single
2505
+ * specified Table, sorted by a single specified Cell.
2506
+ *
2507
+ * The sorting of the rows is alphanumeric, and you can indicate whether it
2508
+ * should be in descending order. The `offset` and `limit` parameters are used
2509
+ * to paginate results, but default to `0` and `undefined` to return all
2510
+ * available Row Ids if not specified.
2511
+ *
2512
+ * Use the optional mutator parameter to indicate that there is code in the
2513
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2514
+ * mutations will be silently ignored. All relevant mutator listeners (with
2515
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2516
+ * (since the latter may become relevant due to changes made in the former).
2517
+ * The changes made by mutator listeners do not fire other mutating listeners,
2518
+ * though they will fire non-mutator listeners.
2519
+ *
2520
+ * @param tableId The Id of the Table to listen to.
2521
+ * @param cellId The Id of the Cell whose values are used for the sorting, or
2522
+ * `undefined` to by sort the Row Id itself.
2523
+ * @param descending Whether the sorting should be in descending order.
2524
+ * @param offset The number of Row Ids to skip for pagination purposes, if
2525
+ * any.
2526
+ * @param limit The maximum number of Row Ids to return, or `undefined` for
2527
+ * all.
2528
+ * @param listener The function that will be called whenever the sorted Row
2529
+ * Ids in the Table change.
2530
+ * @param mutator An optional boolean that indicates that the listener mutates
2531
+ * Store data.
2532
+ * @returns A unique Id for the listener that can later be used to call it
2533
+ * explicitly, or to remove it.
2534
+ * @example
2535
+ * This example registers a listener that responds to any change to the sorted
2536
+ * Row Ids of a specific Table.
2537
+ *
2538
+ * ```js
2539
+ * const store = createStore().setTables({
2540
+ * pets: {
2541
+ * cujo: {species: 'wolf'},
2542
+ * felix: {species: 'cat'},
2543
+ * },
2544
+ * });
2545
+ * console.log(store.getSortedRowIds('pets', 'species', false));
2546
+ * // -> ['felix', 'cujo']
2547
+ *
2548
+ * const listenerId = store.addSortedRowIdsListener(
2549
+ * 'pets',
2550
+ * 'species',
2551
+ * false,
2552
+ * 0,
2553
+ * undefined,
2554
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2555
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2556
+ * console.log(sortedRowIds);
2557
+ * // ^ cheaper than calling getSortedRowIds again
2558
+ * },
2559
+ * );
2560
+ *
2561
+ * store.setRow('pets', 'fido', {species: 'dog'});
2562
+ * // -> 'Sorted Row Ids for pets table changed'
2563
+ * // -> ['felix', 'fido', 'cujo']
2564
+ *
2565
+ * store.delListener(listenerId);
2566
+ * ```
2567
+ * @example
2568
+ * This 111example registers a listener that responds to any change to a
2569
+ * paginated section of the sorted Row Ids of a specific Table.
2570
+ *
2571
+ * ```js
2572
+ * const store = createStore().setTables({
2573
+ * pets: {
2574
+ * fido: {price: 6},
2575
+ * felix: {price: 5},
2576
+ * mickey: {price: 2},
2577
+ * tom: {price: 4},
2578
+ * carnaby: {price: 3},
2579
+ * lowly: {price: 1},
2580
+ * },
2581
+ * });
2582
+ *
2583
+ * const listenerId = store.addSortedRowIdsListener(
2584
+ * 'pets',
2585
+ * 'price',
2586
+ * false,
2587
+ * 0,
2588
+ * 3,
2589
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2590
+ * console.log(`First three sorted Row Ids for ${tableId} table changed`);
2591
+ * console.log(sortedRowIds);
2592
+ * // ^ cheaper than calling getSortedRowIds again
2593
+ * },
2594
+ * );
2595
+ * console.log(store.getSortedRowIds('pets', 'price', false, 0, 3));
2596
+ * // -> ['lowly', 'mickey', 'carnaby']
2597
+ *
2598
+ * store.setCell('pets', 'carnaby', 'price', 4.5);
2599
+ * // -> 'First three sorted Row Ids for pets table changed'
2600
+ * // -> ['lowly', 'mickey', 'tom']
2601
+ *
2602
+ * store.delListener(listenerId);
2603
+ * ```
2604
+ * @example
2605
+ * This example registers a listener that responds to any change to the sorted
2606
+ * Row Ids of a specific Table. The Row Ids are sorted by their own value,
2607
+ * since the `cellId` parameter is explicitly undefined.
2608
+ *
2609
+ * ```js
2610
+ * const store = createStore().setTables({
2611
+ * pets: {
2612
+ * fido: {species: 'dog'},
2613
+ * felix: {species: 'cat'},
2614
+ * },
2615
+ * });
2616
+ * console.log(store.getSortedRowIds('pets', undefined, false));
2617
+ * // -> ['felix', 'fido']
2618
+ *
2619
+ * const listenerId = store.addSortedRowIdsListener(
2620
+ * 'pets',
2621
+ * undefined,
2622
+ * false,
2623
+ * 0,
2624
+ * undefined,
2625
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2626
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2627
+ * console.log(sortedRowIds);
2628
+ * // ^ cheaper than calling getSortedRowIds again
2629
+ * },
2630
+ * );
2631
+ *
2632
+ * store.setRow('pets', 'cujo', {species: 'wolf'});
2633
+ * // -> 'Sorted Row Ids for pets table changed'
2634
+ * // -> ['cujo', 'felix', 'fido']
2635
+ *
2636
+ * store.delListener(listenerId);
2637
+ * ```
2638
+ * @example
2639
+ * This example registers a listener that responds to a change in the sorting
2640
+ * of the rows of a specific Table, even though the set of Ids themselves has
2641
+ * not changed.
2642
+ *
2643
+ * ```js
2644
+ * const store = createStore().setTables({
2645
+ * pets: {
2646
+ * fido: {species: 'dog'},
2647
+ * felix: {species: 'cat'},
2648
+ * },
2649
+ * });
2650
+ * console.log(store.getSortedRowIds('pets', 'species', false));
2651
+ * // -> ['felix', 'fido']
2652
+ *
2653
+ * const listenerId = store.addSortedRowIdsListener(
2654
+ * 'pets',
2655
+ * 'species',
2656
+ * false,
2657
+ * 0,
2658
+ * undefined,
2659
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2660
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2661
+ * console.log(sortedRowIds);
2662
+ * // ^ cheaper than calling getSortedRowIds again
2663
+ * },
2664
+ * );
2665
+ *
2666
+ * store.setCell('pets', 'felix', 'species', 'tiger');
2667
+ * // -> 'Sorted Row Ids for pets table changed'
2668
+ * // -> ['fido', 'felix']
2669
+ *
2670
+ * store.delListener(listenerId);
2671
+ * ```
2672
+ * @example
2673
+ * This example registers a listener that responds to any change to the sorted
2674
+ * Row Ids of a specific Table, and which also mutates the Store itself.
2675
+ *
2676
+ * ```js
2677
+ * const store = createStore().setTables({
2678
+ * pets: {
2679
+ * cujo: {species: 'wolf'},
2680
+ * felix: {species: 'cat'},
2681
+ * },
2682
+ * });
2683
+ * const listenerId = store.addSortedRowIdsListener(
2684
+ * 'pets',
2685
+ * 'species',
2686
+ * false,
2687
+ * 0,
2688
+ * undefined,
2689
+ * (store, tableId) => store.setCell('meta', 'sorted', tableId, true),
2690
+ * true, // mutator
2691
+ * );
2692
+ *
2693
+ * store.setRow('pets', 'fido', {species: 'dog'});
2694
+ * console.log(store.getTable('meta'));
2695
+ * // -> {sorted: {pets: true}}
2696
+ *
2697
+ * store.delListener(listenerId);
2698
+ * ```
2699
+ * @category Listener
2700
+ * @since v2.0.0
2701
+ */
2702
+ addSortedRowIdsListener(
2703
+ tableId: Id,
2704
+ cellId: Id | undefined,
2705
+ descending: boolean,
2706
+ offset: number,
2707
+ limit: number | undefined,
2708
+ listener: SortedRowIdsListener,
2398
2709
  mutator?: boolean,
2399
2710
  ): Id;
2400
2711
 
@@ -2528,12 +2839,6 @@ export interface Store {
2528
2839
  * Table, any Row in a specific Table, a specific Row in any Table, or any Row
2529
2840
  * in any Table.
2530
2841
  *
2531
- * Since v2.0.0, you can use the optional `trackReorder` parameter to
2532
- * additionally track when the set of Ids has not changed, but the order has -
2533
- * for example when a Cell from the middle of the Row is removed and then
2534
- * added back within the same transaction. This behavior is disabled by
2535
- * default due to the potential performance cost of detecting such changes.
2536
- *
2537
2842
  * Use the optional mutator parameter to indicate that there is code in the
2538
2843
  * listener that will mutate Store data. If set to `false` (or omitted), such
2539
2844
  * mutations will be silently ignored. All relevant mutator listeners (with
@@ -2546,9 +2851,6 @@ export interface Store {
2546
2851
  * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2547
2852
  * @param listener The function that will be called whenever the Cell Ids in
2548
2853
  * the Row change.
2549
- * @param trackReorder An optional boolean that indicates that the listener
2550
- * should be called if the set of Ids remains the same but their order
2551
- * changes.
2552
2854
  * @param mutator An optional boolean that indicates that the listener mutates
2553
2855
  * Store data.
2554
2856
  * @returns A unique Id for the listener that can later be used to call it
@@ -2605,7 +2907,6 @@ export interface Store {
2605
2907
  * 'fido',
2606
2908
  * (store, tableId, rowId) =>
2607
2909
  * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
2608
- * false, // track reorder
2609
2910
  * true, // mutator
2610
2911
  * );
2611
2912
  *
@@ -2621,7 +2922,6 @@ export interface Store {
2621
2922
  tableId: IdOrNull,
2622
2923
  rowId: IdOrNull,
2623
2924
  listener: CellIdsListener,
2624
- trackReorder?: boolean,
2625
2925
  mutator?: boolean,
2626
2926
  ): Id;
2627
2927