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
@@ -14,6 +14,18 @@ const SUM = 'sum';
14
14
  const AVG = 'avg';
15
15
  const MIN = 'min';
16
16
  const MAX = 'max';
17
+ const LISTENER = 'Listener';
18
+ const RESULT = 'Result';
19
+ const GET = 'get';
20
+ const ADD = 'add';
21
+ const TABLES = 'Tables';
22
+ const TABLE_IDS = 'TableIds';
23
+ const TABLE = 'Table';
24
+ const ROW_IDS = 'RowIds';
25
+ const SORTED_ROW_IDS = 'SortedRowIds';
26
+ const ROW = 'Row';
27
+ const CELL_IDS = 'CellIds';
28
+ const CELL = 'Cell';
17
29
 
18
30
  const arrayHas = (array, value) => array.includes(value);
19
31
  const arrayEvery = (array, cb) => array.every(cb);
@@ -86,7 +98,7 @@ const mapSet = (map, key, value) =>
86
98
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
87
99
  const mapEnsure = (map, key, getDefaultValue) => {
88
100
  if (!collHas(map, key)) {
89
- map.set(key, getDefaultValue());
101
+ mapSet(map, key, getDefaultValue());
90
102
  }
91
103
  return mapGet(map, key);
92
104
  };
@@ -284,32 +296,32 @@ const getCreateFunction = (getFunction) => {
284
296
  };
285
297
 
286
298
  const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
287
- const sets = [];
288
- const deep = (set, p) =>
299
+ const leaves = [];
300
+ const deep = (node, p) =>
289
301
  p == arrayLength(path)
290
- ? arrayPush(sets, set)
291
- : arrayForEach([path[p], null], (id) => deep(mapGet(set, id), p + 1));
302
+ ? arrayPush(leaves, node)
303
+ : path[p] === null
304
+ ? collForEach(node, (node2) => deep(node2, p + 1))
305
+ : arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
292
306
  deep(deepIdSet, 0);
293
- return sets;
307
+ return leaves;
294
308
  };
295
309
  const getListenerFunctions = (getThing) => {
296
310
  let thing;
297
311
  let nextId = 0;
298
312
  const listenerPool = [];
299
313
  const allListeners = mapNew();
300
- const addListener = (listener, idSetNode, idOrNulls) => {
314
+ const addListener = (listener, idSetNode, path) => {
301
315
  thing ??= getThing();
302
316
  const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
303
- mapSet(allListeners, id, [listener, idSetNode, idOrNulls]);
304
- setAdd(visitTree(idSetNode, idOrNulls ?? [EMPTY_STRING], setNew), id);
317
+ mapSet(allListeners, id, [listener, idSetNode, path]);
318
+ setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
305
319
  return id;
306
320
  };
307
321
  const callListeners = (idSetNode, ids, ...extraArgs) =>
308
322
  arrayForEach(getWildcardedLeaves(idSetNode, ids), (set) =>
309
323
  collForEach(set, (id) =>
310
- ifNotUndefined(mapGet(allListeners, id), ([listener]) =>
311
- listener(thing, ...(ids ?? []), ...extraArgs),
312
- ),
324
+ mapGet(allListeners, id)[0](thing, ...(ids ?? []), ...extraArgs),
313
325
  ),
314
326
  );
315
327
  const delListener = (id) =>
@@ -324,8 +336,6 @@ const getListenerFunctions = (getThing) => {
324
336
  }
325
337
  return idOrNulls;
326
338
  });
327
- const hasListeners = (idSetNode, ids) =>
328
- !arrayEvery(getWildcardedLeaves(idSetNode, ids), isUndefined);
329
339
  const callListener = (id, idNullGetters, extraArgsGetter) =>
330
340
  ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls = []]) => {
331
341
  const callWithIds = (...ids) => {
@@ -340,7 +350,7 @@ const getListenerFunctions = (getThing) => {
340
350
  };
341
351
  callWithIds();
342
352
  });
343
- return [addListener, callListeners, delListener, hasListeners, callListener];
353
+ return [addListener, callListeners, delListener, callListener];
344
354
  };
345
355
 
346
356
  const object = Object;
@@ -565,6 +575,7 @@ const createCheckpoints = getCreateFunction((store) => {
565
575
  });
566
576
 
567
577
  const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
578
+ const id = (key) => EMPTY_STRING + key;
568
579
 
569
580
  const createIndexes = getCreateFunction((store) => {
570
581
  const sliceIdsListeners = mapNew();
@@ -1081,6 +1092,7 @@ const createRemotePersister = (
1081
1092
  };
1082
1093
 
1083
1094
  const createQueries = getCreateFunction((store) => {
1095
+ const createStore = store.createStore;
1084
1096
  const [
1085
1097
  getStore,
1086
1098
  getQueryIds,
@@ -1096,25 +1108,26 @@ const createQueries = getCreateFunction((store) => {
1096
1108
  addStoreListeners,
1097
1109
  delStoreListeners,
1098
1110
  ] = getDefinableFunctions(store, () => true, getUndefined);
1099
- const preStore1 = store.createStore();
1100
- const preStore2 = store.createStore();
1101
- const resultStore = store.createStore();
1111
+ const preStore = createStore();
1112
+ const resultStore = createStore();
1102
1113
  const preStoreListenerIds = mapNew();
1103
- const addPreStoreListener = (preStore, queryId, ...listenerIds) =>
1114
+ const addPreStoreListener = (preStore2, queryId, ...listenerIds) =>
1104
1115
  arrayForEach(listenerIds, (listenerId) =>
1105
1116
  setAdd(
1106
1117
  mapEnsure(
1107
1118
  mapEnsure(preStoreListenerIds, queryId, mapNew),
1108
- preStore,
1119
+ preStore2,
1109
1120
  setNew,
1110
1121
  ),
1111
1122
  listenerId,
1112
1123
  ),
1113
1124
  );
1125
+ const cleanPreStores = (queryId) =>
1126
+ arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
1114
1127
  const synchronizeTransactions = (queryId, fromStore, toStore) =>
1115
- addStoreListeners(
1128
+ addPreStoreListener(
1129
+ fromStore,
1116
1130
  queryId,
1117
- 0,
1118
1131
  fromStore.addWillFinishTransactionListener(toStore.startTransaction),
1119
1132
  fromStore.addDidFinishTransactionListener(() =>
1120
1133
  toStore.finishTransaction(),
@@ -1122,16 +1135,12 @@ const createQueries = getCreateFunction((store) => {
1122
1135
  );
1123
1136
  const setQueryDefinition = (queryId, tableId, build) => {
1124
1137
  setDefinition(queryId, tableId);
1125
- preStore1.delTable(queryId);
1126
- preStore2.delTable(queryId);
1127
- resultStore.delTable(queryId);
1128
- let offsetLimit;
1138
+ cleanPreStores(queryId);
1129
1139
  const selectEntries = [];
1130
1140
  const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
1131
1141
  const wheres = [];
1132
1142
  const groupEntries = [];
1133
1143
  const havings = [];
1134
- const orders = [];
1135
1144
  const select = (arg1, arg2) => {
1136
1145
  const selectEntry = isFunction(arg1)
1137
1146
  ? [arrayLength(selectEntries) + EMPTY_STRING, arg1]
@@ -1197,17 +1206,7 @@ const createQueries = getCreateFunction((store) => {
1197
1206
  : (getSelectedOrGroupedCell) =>
1198
1207
  getSelectedOrGroupedCell(arg1) === arg2,
1199
1208
  );
1200
- const order = (arg1, descending) =>
1201
- arrayPush(orders, [
1202
- isFunction(arg1)
1203
- ? arg1
1204
- : (getSelectedOrGroupedCell) => getSelectedOrGroupedCell(arg1) ?? 0,
1205
- descending,
1206
- ]);
1207
- const limit = (arg1, arg2) => {
1208
- offsetLimit = isUndefined(arg2) ? [0, arg1] : [arg1, arg2];
1209
- };
1210
- build({select, join, where, group, having, order, limit});
1209
+ build({select, join, where, group, having});
1211
1210
  const selects = mapNew(selectEntries);
1212
1211
  if (collIsEmpty(selects)) {
1213
1212
  return queries;
@@ -1219,95 +1218,11 @@ const createQueries = getCreateFunction((store) => {
1219
1218
  ),
1220
1219
  );
1221
1220
  const groups = mapNew(groupEntries);
1222
- let selectJoinWhereStore = preStore1;
1223
- let groupHavingStore = preStore2;
1224
- if (arrayIsEmpty(orders) && isUndefined(offsetLimit)) {
1225
- groupHavingStore = resultStore;
1226
- } else {
1227
- synchronizeTransactions(queryId, groupHavingStore, resultStore);
1228
- const groupRowIdSorter = (rowId1, rowId2) => {
1229
- const sortKeys1 = mapGet(sortKeysByGroupRowId, rowId1) ?? [];
1230
- const sortKeys2 = mapGet(sortKeysByGroupRowId, rowId2) ?? [];
1231
- const orderIndex = orders.findIndex(
1232
- (_order, index) => sortKeys1[index] !== sortKeys2[index],
1233
- );
1234
- return orderIndex < 0
1235
- ? 0
1236
- : defaultSorter(sortKeys1[orderIndex], sortKeys2[orderIndex]) *
1237
- (orders[orderIndex][1] ? -1 : 1);
1238
- };
1239
- const sortKeysByGroupRowId = mapNew();
1240
- const sortedGroupRowIds = mapNew();
1241
- addPreStoreListener(
1242
- groupHavingStore,
1243
- queryId,
1244
- arrayIsEmpty(orders)
1245
- ? groupHavingStore.addRowIdsListener(queryId, () =>
1246
- collClear(sortedGroupRowIds),
1247
- )
1248
- : groupHavingStore.addRowListener(
1249
- queryId,
1250
- null,
1251
- (_store, _tableId, groupRowId) => {
1252
- let newSortKeys = null;
1253
- if (groupHavingStore.hasRow(queryId, groupRowId)) {
1254
- const oldSortKeys =
1255
- mapGet(sortKeysByGroupRowId, groupRowId) ?? [];
1256
- const groupRow = groupHavingStore.getRow(queryId, groupRowId);
1257
- const getCell = (getSelectedOrGroupedCell) =>
1258
- groupRow[getSelectedOrGroupedCell];
1259
- newSortKeys = arrayMap(orders, ([getSortKey]) =>
1260
- getSortKey(getCell, groupRowId),
1261
- );
1262
- if (arrayIsEqual(oldSortKeys, newSortKeys)) {
1263
- if (mapGet(sortedGroupRowIds, groupRowId)) {
1264
- resultStore.setRow(queryId, groupRowId, groupRow);
1265
- }
1266
- return;
1267
- }
1268
- }
1269
- mapSet(sortKeysByGroupRowId, groupRowId, newSortKeys);
1270
- collClear(sortedGroupRowIds);
1271
- },
1272
- ),
1273
- groupHavingStore.addTableListener(queryId, () => {
1274
- if (collIsEmpty(sortedGroupRowIds)) {
1275
- resultStore.delTable(queryId);
1276
- if (groupHavingStore.hasTable(queryId)) {
1277
- const groupTable = groupHavingStore.getTable(queryId);
1278
- arrayForEach(
1279
- arraySort(objIds(groupTable), groupRowIdSorter),
1280
- (id) => mapSet(sortedGroupRowIds, id, 0),
1281
- );
1282
- arrayForEach(
1283
- ifNotUndefined(
1284
- offsetLimit,
1285
- ([offset, limit2]) =>
1286
- arraySlice(
1287
- mapKeys(sortedGroupRowIds),
1288
- offset,
1289
- offset + limit2,
1290
- ),
1291
- () => mapKeys(sortedGroupRowIds),
1292
- ),
1293
- (groupRowId) => {
1294
- resultStore.setRow(
1295
- queryId,
1296
- groupRowId,
1297
- groupTable[groupRowId],
1298
- );
1299
- mapSet(sortedGroupRowIds, groupRowId, 1);
1300
- },
1301
- );
1302
- }
1303
- }
1304
- }),
1305
- );
1306
- }
1221
+ let selectJoinWhereStore = preStore;
1307
1222
  if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
1308
- selectJoinWhereStore = groupHavingStore;
1223
+ selectJoinWhereStore = resultStore;
1309
1224
  } else {
1310
- synchronizeTransactions(queryId, selectJoinWhereStore, groupHavingStore);
1225
+ synchronizeTransactions(queryId, selectJoinWhereStore, resultStore);
1311
1226
  const groupedSelectedCellIds = mapNew();
1312
1227
  mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
1313
1228
  setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
@@ -1369,8 +1284,8 @@ const createQueries = getCreateFunction((store) => {
1369
1284
  !arrayEvery(havings, (having2) =>
1370
1285
  having2((cellId) => groupRow[cellId]),
1371
1286
  )
1372
- ? groupHavingStore.delRow
1373
- : groupHavingStore.setRow)(queryId, groupRowId, groupRow);
1287
+ ? resultStore.delRow
1288
+ : resultStore.setRow)(queryId, groupRowId, groupRow);
1374
1289
  },
1375
1290
  );
1376
1291
  addPreStoreListener(
@@ -1417,7 +1332,7 @@ const createQueries = getCreateFunction((store) => {
1417
1332
  ([, selectedRowIds, groupRowId]) => {
1418
1333
  collDel(selectedRowIds, selectedRowId);
1419
1334
  if (collIsEmpty(selectedRowIds)) {
1420
- groupHavingStore.delRow(queryId, groupRowId);
1335
+ resultStore.delRow(queryId, groupRowId);
1421
1336
  return 1;
1422
1337
  }
1423
1338
  },
@@ -1447,7 +1362,7 @@ const createQueries = getCreateFunction((store) => {
1447
1362
  return [
1448
1363
  mapNew(),
1449
1364
  setNew(),
1450
- groupHavingStore.addRow(queryId, groupRow, 1),
1365
+ resultStore.addRow(queryId, groupRow, 1),
1451
1366
  groupRow,
1452
1367
  ];
1453
1368
  },
@@ -1554,56 +1469,15 @@ const createQueries = getCreateFunction((store) => {
1554
1469
  return queries;
1555
1470
  };
1556
1471
  const delQueryDefinition = (queryId) => {
1557
- mapForEach(mapGet(preStoreListenerIds, queryId), (preStore, listenerIds) =>
1472
+ mapForEach(mapGet(preStoreListenerIds, queryId), (preStore2, listenerIds) =>
1558
1473
  collForEach(listenerIds, (listenerId) =>
1559
- preStore.delListener(listenerId),
1474
+ preStore2.delListener(listenerId),
1560
1475
  ),
1561
1476
  );
1477
+ cleanPreStores(queryId);
1562
1478
  delDefinition(queryId);
1563
1479
  return queries;
1564
1480
  };
1565
- const getResultTable = (queryId) => resultStore.getTable(queryId);
1566
- const getResultRowIds = (queryId) => resultStore.getRowIds(queryId);
1567
- const getResultRow = (queryId, rowId) => resultStore.getRow(queryId, rowId);
1568
- const getResultCellIds = (queryId, rowId) =>
1569
- resultStore.getCellIds(queryId, rowId);
1570
- const getResultCell = (queryId, rowId, cellId) =>
1571
- resultStore.getCell(queryId, rowId, cellId);
1572
- const hasResultTable = (queryId) => resultStore.hasTable(queryId);
1573
- const hasResultRow = (queryId, rowId) => resultStore.hasRow(queryId, rowId);
1574
- const hasResultCell = (queryId, rowId, cellId) =>
1575
- resultStore.hasCell(queryId, rowId, cellId);
1576
- const forEachResultTable = (tableCallback) =>
1577
- resultStore.forEachTable(tableCallback);
1578
- const forEachResultRow = (queryId, rowCallback) =>
1579
- resultStore.forEachRow(queryId, rowCallback);
1580
- const forEachResultCell = (queryId, rowId, cellCallback) =>
1581
- resultStore.forEachCell(queryId, rowId, cellCallback);
1582
- const addResultTableListener = (queryId, listener) =>
1583
- resultStore.addTableListener(queryId, (_store, ...args) =>
1584
- listener(queries, ...args),
1585
- );
1586
- const addResultRowIdsListener = (queryId, listener, trackReorder) =>
1587
- resultStore.addRowIdsListener(
1588
- queryId,
1589
- (_store, ...args) => listener(queries, ...args),
1590
- trackReorder,
1591
- );
1592
- const addResultRowListener = (queryId, rowId, listener) =>
1593
- resultStore.addRowListener(queryId, rowId, (_store, ...args) =>
1594
- listener(queries, ...args),
1595
- );
1596
- const addResultCellIdsListener = (queryId, rowId, listener, trackReorder) =>
1597
- resultStore.addCellIdsListener(
1598
- queryId,
1599
- rowId,
1600
- (_store, ...args) => listener(queries, ...args),
1601
- trackReorder,
1602
- );
1603
- const addResultCellListener = (queryId, rowId, cellId, listener) =>
1604
- resultStore.addCellListener(queryId, rowId, cellId, (_store, ...args) =>
1605
- listener(queries, ...args),
1606
- );
1607
1481
  const delListener = (listenerId) => {
1608
1482
  resultStore.delListener(listenerId);
1609
1483
  return queries;
@@ -1625,26 +1499,34 @@ const createQueries = getCreateFunction((store) => {
1625
1499
  forEachQuery,
1626
1500
  hasQuery,
1627
1501
  getTableId,
1628
- getResultTable,
1629
- getResultRowIds,
1630
- getResultRow,
1631
- getResultCellIds,
1632
- getResultCell,
1633
- hasResultTable,
1634
- hasResultRow,
1635
- hasResultCell,
1636
- forEachResultTable,
1637
- forEachResultRow,
1638
- forEachResultCell,
1639
- addResultTableListener,
1640
- addResultRowIdsListener,
1641
- addResultRowListener,
1642
- addResultCellIdsListener,
1643
- addResultCellListener,
1644
1502
  delListener,
1645
1503
  destroy,
1646
1504
  getListenerStats,
1647
1505
  };
1506
+ objForEach(
1507
+ {
1508
+ [TABLE]: [1, 1],
1509
+ [ROW_IDS]: [0, 1],
1510
+ [SORTED_ROW_IDS]: [0, 5],
1511
+ [ROW]: [1, 2],
1512
+ [CELL_IDS]: [0, 2],
1513
+ [CELL]: [1, 3],
1514
+ },
1515
+ ([hasAndForEach, argumentCount], gettable) => {
1516
+ arrayForEach(
1517
+ hasAndForEach ? [GET, 'has', 'forEach'] : [GET],
1518
+ (prefix) =>
1519
+ (queries[prefix + RESULT + gettable] = (...args) =>
1520
+ resultStore[prefix + gettable](...args)),
1521
+ );
1522
+ queries[ADD + RESULT + gettable + LISTENER] = (...args) =>
1523
+ resultStore[ADD + gettable + LISTENER](
1524
+ ...arraySlice(args, 0, argumentCount),
1525
+ (_store, ...listenerArgs) =>
1526
+ args[argumentCount](queries, ...listenerArgs),
1527
+ );
1528
+ },
1529
+ );
1648
1530
  return objFreeze(queries);
1649
1531
  });
1650
1532
 
@@ -1837,21 +1719,17 @@ const createRelationships = getCreateFunction((store) => {
1837
1719
 
1838
1720
  const pairNew = (value) => [value, value];
1839
1721
  const pairCollSize2 = (pair, func = collSize2) => func(pair[0]) + func(pair[1]);
1840
- const pairCollIsEmpty = (pair) => pairCollSize2(pair) == 0;
1841
1722
  const pairNewMap = () => [mapNew(), mapNew()];
1842
- const pair2CollSize2 = (pair2, func = collSize2) =>
1843
- pairCollSize2(pair2[0], func) + pairCollSize2(pair2[1], func);
1844
- const pair2NewMap = () => [pairNewMap(), pairNewMap()];
1845
1723
 
1846
1724
  const transformMap = (map, toBeLikeObject, setId, delId = mapSet) => {
1847
1725
  const idsToDelete = arrayFilter(
1848
1726
  mapKeys(map),
1849
- (id) => !objHas(toBeLikeObject, id),
1727
+ (id2) => !objHas(toBeLikeObject, id2),
1850
1728
  );
1851
- arrayForEach(objIds(toBeLikeObject), (id) =>
1852
- setId(map, id, toBeLikeObject[id]),
1729
+ arrayForEach(objIds(toBeLikeObject), (id2) =>
1730
+ setId(map, id2, toBeLikeObject[id2]),
1853
1731
  );
1854
- arrayForEach(idsToDelete, (id) => delId(map, id));
1732
+ arrayForEach(idsToDelete, (id2) => delId(map, id2));
1855
1733
  return map;
1856
1734
  };
1857
1735
  const validate = (obj, validateChild, onInvalidObj) => {
@@ -1859,15 +1737,15 @@ const validate = (obj, validateChild, onInvalidObj) => {
1859
1737
  onInvalidObj?.();
1860
1738
  return false;
1861
1739
  }
1862
- objForEach(obj, (child, id) => {
1863
- if (!validateChild(child, id)) {
1864
- objDel(obj, id);
1740
+ objForEach(obj, (child, id2) => {
1741
+ if (!validateChild(child, id2)) {
1742
+ objDel(obj, id2);
1865
1743
  }
1866
1744
  });
1867
1745
  return !objIsEmpty(obj);
1868
1746
  };
1869
- const idsChanged = (changedIds, id, added) =>
1870
- mapSet(changedIds, id, mapGet(changedIds, id) == -added ? void 0 : added);
1747
+ const idsChanged = (changedIds, id2, added) =>
1748
+ mapSet(changedIds, id2, mapGet(changedIds, id2) == -added ? void 0 : added);
1871
1749
  const createStore = () => {
1872
1750
  let hasSchema;
1873
1751
  let cellsTouched;
@@ -1882,26 +1760,22 @@ const createStore = () => {
1882
1760
  const schemaRowCache = mapNew();
1883
1761
  const tablesMap = mapNew();
1884
1762
  const tablesListeners = pairNewMap();
1885
- const tableIdsListeners = pair2NewMap();
1763
+ const tableIdsListeners = pairNewMap();
1886
1764
  const tableListeners = pairNewMap();
1887
- const rowIdsListeners = pair2NewMap();
1765
+ const rowIdsListeners = pairNewMap();
1766
+ const sortedRowIdsListeners = pairNewMap();
1888
1767
  const rowListeners = pairNewMap();
1889
- const cellIdsListeners = pair2NewMap();
1768
+ const cellIdsListeners = pairNewMap();
1890
1769
  const cellListeners = pairNewMap();
1891
1770
  const invalidCellListeners = pairNewMap();
1892
1771
  const finishTransactionListeners = pairNewMap();
1893
- const [
1894
- addListener,
1895
- callListeners,
1896
- delListenerImpl,
1897
- hasListeners,
1898
- callListenerImpl,
1899
- ] = getListenerFunctions(() => store);
1772
+ const [addListener, callListeners, delListenerImpl, callListenerImpl] =
1773
+ getListenerFunctions(() => store);
1900
1774
  const validateSchema = (schema) =>
1901
1775
  validate(schema, (tableSchema) =>
1902
1776
  validate(tableSchema, (cellSchema) => {
1903
1777
  if (
1904
- !validate(cellSchema, (_child, id) => arrayHas([TYPE, DEFAULT], id))
1778
+ !validate(cellSchema, (_child, id2) => arrayHas([TYPE, DEFAULT], id2))
1905
1779
  ) {
1906
1780
  return false;
1907
1781
  }
@@ -2078,49 +1952,12 @@ const createStore = () => {
2078
1952
  }
2079
1953
  };
2080
1954
  const tableIdsChanged = (tableId, added) =>
2081
- idsChanged(
2082
- collIsEmpty(changedTableIds)
2083
- ? mapSet(
2084
- changedTableIds,
2085
- null,
2086
- hasListeners(tableIdsListeners[0][1]) ||
2087
- hasListeners(tableIdsListeners[1][1])
2088
- ? getTableIds()
2089
- : 0,
2090
- )
2091
- : changedTableIds,
2092
- tableId,
2093
- added,
2094
- );
1955
+ idsChanged(changedTableIds, tableId, added);
2095
1956
  const rowIdsChanged = (tableId, rowId, added) =>
2096
- idsChanged(
2097
- mapEnsure(changedRowIds, tableId, () =>
2098
- mapNew([
2099
- [
2100
- null,
2101
- hasListeners(rowIdsListeners[0][1], [tableId]) ||
2102
- hasListeners(rowIdsListeners[1][1], [tableId])
2103
- ? getRowIds(tableId)
2104
- : 0,
2105
- ],
2106
- ]),
2107
- ),
2108
- rowId,
2109
- added,
2110
- );
1957
+ idsChanged(mapEnsure(changedRowIds, tableId, mapNew), rowId, added);
2111
1958
  const cellIdsChanged = (tableId, rowId, cellId, added) =>
2112
1959
  idsChanged(
2113
- mapEnsure(mapEnsure(changedCellIds, tableId, mapNew), rowId, () =>
2114
- mapNew([
2115
- [
2116
- null,
2117
- hasListeners(cellIdsListeners[0][1], [tableId, rowId]) ||
2118
- hasListeners(cellIdsListeners[1][1], [tableId, rowId])
2119
- ? getCellIds(tableId, rowId)
2120
- : 0,
2121
- ],
2122
- ]),
2123
- ),
1960
+ mapEnsure(mapEnsure(changedCellIds, tableId, mapNew), rowId, mapNew),
2124
1961
  cellId,
2125
1962
  added,
2126
1963
  );
@@ -2163,23 +2000,21 @@ const createStore = () => {
2163
2000
  ),
2164
2001
  )
2165
2002
  : 0;
2166
- const callIdsListenersIfChanged = (listeners, changedIds, getIds, ids) => {
2167
- if (collSize(changedIds) > 1) {
2168
- callListeners(listeners[0], ids);
2169
- callListeners(listeners[1], ids);
2170
- } else if (
2171
- !collIsEmpty(changedIds) &&
2172
- mapGet(changedIds, null) != 0 &&
2173
- !arrayIsEqual(mapGet(changedIds, null), getIds(...(ids ?? [])))
2174
- ) {
2175
- callListeners(listeners[1], ids);
2003
+ const callIdsListenersIfChanged = (listeners, changedIds, ids) => {
2004
+ if (!collIsEmpty(changedIds)) {
2005
+ callListeners(listeners, ids);
2006
+ return 1;
2176
2007
  }
2177
2008
  };
2178
2009
  const callListenersForChanges = (mutator) => {
2010
+ const emptySortedRowIdListeners = collIsEmpty(
2011
+ sortedRowIdsListeners[mutator],
2012
+ );
2179
2013
  const emptyIdListeners =
2180
- pairCollIsEmpty(cellIdsListeners[mutator]) &&
2181
- pairCollIsEmpty(rowIdsListeners[mutator]) &&
2182
- pairCollIsEmpty(tableIdsListeners[mutator]);
2014
+ collIsEmpty(cellIdsListeners[mutator]) &&
2015
+ collIsEmpty(rowIdsListeners[mutator]) &&
2016
+ emptySortedRowIdListeners &&
2017
+ collIsEmpty(tableIdsListeners[mutator]);
2183
2018
  const emptyOtherListeners =
2184
2019
  collIsEmpty(cellListeners[mutator]) &&
2185
2020
  collIsEmpty(rowListeners[mutator]) &&
@@ -2197,27 +2032,45 @@ const createStore = () => {
2197
2032
  if (!emptyIdListeners) {
2198
2033
  collForEach(changes[2], (rowCellIds, tableId) =>
2199
2034
  collForEach(rowCellIds, (changedIds, rowId) =>
2200
- callIdsListenersIfChanged(
2201
- cellIdsListeners[mutator],
2202
- changedIds,
2203
- getCellIds,
2204
- [tableId, rowId],
2205
- ),
2035
+ callIdsListenersIfChanged(cellIdsListeners[mutator], changedIds, [
2036
+ tableId,
2037
+ rowId,
2038
+ ]),
2206
2039
  ),
2207
2040
  );
2208
- collForEach(changes[1], (changedIds, tableId) =>
2209
- callIdsListenersIfChanged(
2210
- rowIdsListeners[mutator],
2211
- changedIds,
2212
- getRowIds,
2213
- [tableId],
2214
- ),
2215
- );
2216
- callIdsListenersIfChanged(
2217
- tableIdsListeners[mutator],
2218
- changes[0],
2219
- getTableIds,
2220
- );
2041
+ const calledSortableTableIds = setNew();
2042
+ collForEach(changes[1], (changedIds, tableId) => {
2043
+ if (
2044
+ callIdsListenersIfChanged(rowIdsListeners[mutator], changedIds, [
2045
+ tableId,
2046
+ ]) &&
2047
+ !emptySortedRowIdListeners
2048
+ ) {
2049
+ callListeners(sortedRowIdsListeners[mutator], [tableId, null]);
2050
+ setAdd(calledSortableTableIds, tableId);
2051
+ }
2052
+ });
2053
+ if (!emptySortedRowIdListeners) {
2054
+ collForEach(changes[3], (rows, tableId) => {
2055
+ if (!collHas(calledSortableTableIds, tableId)) {
2056
+ const sortableCellIds = setNew();
2057
+ collForEach(rows, (cells) =>
2058
+ collForEach(cells, ([oldCell, newCell], cellId) =>
2059
+ newCell !== oldCell
2060
+ ? setAdd(sortableCellIds, cellId)
2061
+ : collDel(cells, cellId),
2062
+ ),
2063
+ );
2064
+ collForEach(sortableCellIds, (cellId) =>
2065
+ callListeners(sortedRowIdsListeners[mutator], [
2066
+ tableId,
2067
+ cellId,
2068
+ ]),
2069
+ );
2070
+ }
2071
+ });
2072
+ }
2073
+ callIdsListenersIfChanged(tableIdsListeners[mutator], changes[0]);
2221
2074
  }
2222
2075
  if (!emptyOtherListeners) {
2223
2076
  let tablesChanged;
@@ -2255,26 +2108,49 @@ const createStore = () => {
2255
2108
  }
2256
2109
  }
2257
2110
  };
2258
- const fluentTransaction = (actions) => {
2259
- transaction(actions);
2111
+ const fluentTransaction = (actions, ...args) => {
2112
+ transaction(() => actions(...arrayMap(args, id)));
2260
2113
  return store;
2261
2114
  };
2262
2115
  const getTables = () =>
2263
2116
  mapToObj(tablesMap, (table) => mapToObj(table, mapToObj));
2264
2117
  const getTableIds = () => mapKeys(tablesMap);
2265
- const getTable = (tableId) => mapToObj(mapGet(tablesMap, tableId), mapToObj);
2266
- const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, tableId));
2118
+ const getTable = (tableId) =>
2119
+ mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
2120
+ const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
2121
+ const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) => {
2122
+ const cells = [];
2123
+ mapForEach(mapGet(tablesMap, id(tableId)), (rowId, row) =>
2124
+ arrayPush(cells, [
2125
+ isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
2126
+ rowId,
2127
+ ]),
2128
+ );
2129
+ return arrayMap(
2130
+ arraySlice(
2131
+ arraySort(
2132
+ cells,
2133
+ ([cell1], [cell2]) =>
2134
+ defaultSorter(cell1, cell2) * (descending ? -1 : 1),
2135
+ ),
2136
+ offset,
2137
+ isUndefined(limit) ? limit : offset + limit,
2138
+ ),
2139
+ ([, rowId]) => rowId,
2140
+ );
2141
+ };
2267
2142
  const getRow = (tableId, rowId) =>
2268
- mapToObj(mapGet(mapGet(tablesMap, tableId), rowId));
2143
+ mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
2269
2144
  const getCellIds = (tableId, rowId) =>
2270
- mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
2145
+ mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
2271
2146
  const getCell = (tableId, rowId, cellId) =>
2272
- mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
2147
+ mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
2273
2148
  const hasTables = () => !collIsEmpty(tablesMap);
2274
- const hasTable = (tableId) => collHas(tablesMap, tableId);
2275
- const hasRow = (tableId, rowId) => collHas(mapGet(tablesMap, tableId), rowId);
2149
+ const hasTable = (tableId) => collHas(tablesMap, id(tableId));
2150
+ const hasRow = (tableId, rowId) =>
2151
+ collHas(mapGet(tablesMap, id(tableId)), id(rowId));
2276
2152
  const hasCell = (tableId, rowId, cellId) =>
2277
- collHas(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
2153
+ collHas(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
2278
2154
  const getJson = () => jsonString(tablesMap);
2279
2155
  const getSchemaJson = () => jsonString(schemaMap);
2280
2156
  const setTables = (tables) =>
@@ -2282,17 +2158,28 @@ const createStore = () => {
2282
2158
  validateTables(tables) ? setValidTables(tables) : 0,
2283
2159
  );
2284
2160
  const setTable = (tableId, table) =>
2285
- fluentTransaction(() =>
2286
- validateTable(table, tableId) ? setValidTable(tableId, table) : 0,
2161
+ fluentTransaction(
2162
+ (tableId2) =>
2163
+ validateTable(table, tableId2) ? setValidTable(tableId2, table) : 0,
2164
+ tableId,
2287
2165
  );
2288
2166
  const setRow = (tableId, rowId, row) =>
2289
- fluentTransaction(() =>
2290
- validateRow(tableId, rowId, row)
2291
- ? setValidRow(tableId, getOrCreateTable(tableId), rowId, row)
2292
- : 0,
2167
+ fluentTransaction(
2168
+ (tableId2, rowId2) =>
2169
+ validateRow(id(tableId2), id(rowId2), row)
2170
+ ? setValidRow(
2171
+ id(tableId2),
2172
+ getOrCreateTable(id(tableId2)),
2173
+ id(rowId2),
2174
+ row,
2175
+ )
2176
+ : 0,
2177
+ tableId,
2178
+ rowId,
2293
2179
  );
2294
2180
  const addRow = (tableId, row, forceId) =>
2295
2181
  transaction(() => {
2182
+ tableId = id(tableId);
2296
2183
  const isValidRow = validateRow(tableId, void 0, row);
2297
2184
  const rowId =
2298
2185
  isValidRow || forceId
@@ -2304,32 +2191,40 @@ const createStore = () => {
2304
2191
  return rowId;
2305
2192
  });
2306
2193
  const setPartialRow = (tableId, rowId, partialRow) =>
2307
- fluentTransaction(() => {
2308
- if (validateRow(tableId, rowId, partialRow, 1)) {
2309
- const table = getOrCreateTable(tableId);
2310
- objForEach(partialRow, (cell, cellId) =>
2311
- setCellIntoDefaultRow(tableId, table, rowId, cellId, cell),
2312
- );
2313
- }
2314
- });
2194
+ fluentTransaction(
2195
+ (tableId2, rowId2) => {
2196
+ if (validateRow(tableId2, rowId2, partialRow, 1)) {
2197
+ const table = getOrCreateTable(tableId2);
2198
+ objForEach(partialRow, (cell, cellId) =>
2199
+ setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
2200
+ );
2201
+ }
2202
+ },
2203
+ tableId,
2204
+ rowId,
2205
+ );
2315
2206
  const setCell = (tableId, rowId, cellId, cell) =>
2316
- fluentTransaction(() =>
2317
- ifNotUndefined(
2318
- getValidatedCell(
2319
- tableId,
2320
- rowId,
2321
- cellId,
2322
- isFunction(cell) ? cell(getCell(tableId, rowId, cellId)) : cell,
2323
- ),
2324
- (validCell) =>
2325
- setCellIntoDefaultRow(
2326
- tableId,
2327
- getOrCreateTable(tableId),
2328
- rowId,
2329
- cellId,
2330
- validCell,
2207
+ fluentTransaction(
2208
+ (tableId2, rowId2, cellId2) =>
2209
+ ifNotUndefined(
2210
+ getValidatedCell(
2211
+ tableId2,
2212
+ rowId2,
2213
+ cellId2,
2214
+ isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
2331
2215
  ),
2332
- ),
2216
+ (validCell) =>
2217
+ setCellIntoDefaultRow(
2218
+ tableId2,
2219
+ getOrCreateTable(tableId2),
2220
+ rowId2,
2221
+ cellId2,
2222
+ validCell,
2223
+ ),
2224
+ ),
2225
+ tableId,
2226
+ rowId,
2227
+ cellId,
2333
2228
  );
2334
2229
  const setJson = (json) => {
2335
2230
  try {
@@ -2350,24 +2245,42 @@ const createStore = () => {
2350
2245
  });
2351
2246
  const delTables = () => fluentTransaction(() => setValidTables({}));
2352
2247
  const delTable = (tableId) =>
2353
- fluentTransaction(() =>
2354
- collHas(tablesMap, tableId) ? delValidTable(tableId) : 0,
2248
+ fluentTransaction(
2249
+ (tableId2) =>
2250
+ collHas(tablesMap, tableId2) ? delValidTable(tableId2) : 0,
2251
+ tableId,
2355
2252
  );
2356
2253
  const delRow = (tableId, rowId) =>
2357
- fluentTransaction(() =>
2358
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
2359
- collHas(tableMap, rowId) ? delValidRow(tableId, tableMap, rowId) : 0,
2360
- ),
2254
+ fluentTransaction(
2255
+ (tableId2, rowId2) =>
2256
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
2257
+ collHas(tableMap, rowId2)
2258
+ ? delValidRow(tableId2, tableMap, rowId2)
2259
+ : 0,
2260
+ ),
2261
+ tableId,
2262
+ rowId,
2361
2263
  );
2362
2264
  const delCell = (tableId, rowId, cellId, forceDel) =>
2363
- fluentTransaction(() =>
2364
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
2365
- ifNotUndefined(mapGet(tableMap, rowId), (rowMap) =>
2366
- collHas(rowMap, cellId)
2367
- ? delValidCell(tableId, tableMap, rowId, rowMap, cellId, forceDel)
2368
- : 0,
2265
+ fluentTransaction(
2266
+ (tableId2, rowId2, cellId2) =>
2267
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
2268
+ ifNotUndefined(mapGet(tableMap, rowId2), (rowMap) =>
2269
+ collHas(rowMap, cellId2)
2270
+ ? delValidCell(
2271
+ tableId2,
2272
+ tableMap,
2273
+ rowId2,
2274
+ rowMap,
2275
+ cellId2,
2276
+ forceDel,
2277
+ )
2278
+ : 0,
2279
+ ),
2369
2280
  ),
2370
- ),
2281
+ tableId,
2282
+ rowId,
2283
+ cellId,
2371
2284
  );
2372
2285
  const delSchema = () =>
2373
2286
  fluentTransaction(() => {
@@ -2422,9 +2335,7 @@ const createStore = () => {
2422
2335
  collForEach(changedCells, (table, tableId) =>
2423
2336
  collForEach(table, (row, rowId) =>
2424
2337
  collForEach(row, ([oldCell], cellId) =>
2425
- isUndefined(oldCell)
2426
- ? delCell(tableId, rowId, cellId, true)
2427
- : setCell(tableId, rowId, cellId, oldCell),
2338
+ setOrDelCell(store, tableId, rowId, cellId, oldCell),
2428
2339
  ),
2429
2340
  ),
2430
2341
  );
@@ -2463,52 +2374,53 @@ const createStore = () => {
2463
2374
  ),
2464
2375
  );
2465
2376
  const forEachRow = (tableId, rowCallback) =>
2466
- collForEach(mapGet(tablesMap, tableId), (rowMap, rowId) =>
2377
+ collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
2467
2378
  rowCallback(rowId, (cellCallback) => mapForEach(rowMap, cellCallback)),
2468
2379
  );
2469
2380
  const forEachCell = (tableId, rowId, cellCallback) =>
2470
- mapForEach(mapGet(mapGet(tablesMap, tableId), rowId), cellCallback);
2471
- const addTablesListener = (listener, mutator) =>
2472
- addListener(listener, tablesListeners[mutator ? 1 : 0]);
2473
- const addTableIdsListener = (listener, trackReorder, mutator) =>
2474
- addListener(
2475
- listener,
2476
- tableIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
2477
- );
2478
- const addTableListener = (tableId, listener, mutator) =>
2479
- addListener(listener, tableListeners[mutator ? 1 : 0], [tableId]);
2480
- const addRowIdsListener = (tableId, listener, trackReorder, mutator) =>
2481
- addListener(
2482
- listener,
2483
- rowIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
2484
- [tableId],
2485
- );
2486
- const addRowListener = (tableId, rowId, listener, mutator) =>
2487
- addListener(listener, rowListeners[mutator ? 1 : 0], [tableId, rowId]);
2488
- const addCellIdsListener = (
2381
+ mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
2382
+ const addSortedRowIdsListener = (
2489
2383
  tableId,
2490
- rowId,
2384
+ cellId,
2385
+ descending,
2386
+ offset,
2387
+ limit,
2491
2388
  listener,
2492
- trackReorder,
2493
2389
  mutator,
2494
- ) =>
2495
- addListener(
2496
- listener,
2497
- cellIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
2498
- [tableId, rowId],
2499
- );
2500
- const addCellListener = (tableId, rowId, cellId, listener, mutator) =>
2501
- addListener(listener, cellListeners[mutator ? 1 : 0], [
2502
- tableId,
2503
- rowId,
2504
- cellId,
2505
- ]);
2506
- const addInvalidCellListener = (tableId, rowId, cellId, listener, mutator) =>
2507
- addListener(listener, invalidCellListeners[mutator ? 1 : 0], [
2390
+ ) => {
2391
+ let sortedRowIds = getSortedRowIds(
2508
2392
  tableId,
2509
- rowId,
2510
2393
  cellId,
2511
- ]);
2394
+ descending,
2395
+ offset,
2396
+ limit,
2397
+ );
2398
+ return addListener(
2399
+ () => {
2400
+ const newSortedRowIds = getSortedRowIds(
2401
+ tableId,
2402
+ cellId,
2403
+ descending,
2404
+ offset,
2405
+ limit,
2406
+ );
2407
+ if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
2408
+ sortedRowIds = newSortedRowIds;
2409
+ listener(
2410
+ store,
2411
+ tableId,
2412
+ cellId,
2413
+ descending,
2414
+ offset,
2415
+ limit,
2416
+ sortedRowIds,
2417
+ );
2418
+ }
2419
+ },
2420
+ sortedRowIdsListeners[mutator ? 1 : 0],
2421
+ [tableId, cellId],
2422
+ );
2423
+ };
2512
2424
  const addWillFinishTransactionListener = (listener) =>
2513
2425
  addListener(listener, finishTransactionListeners[0]);
2514
2426
  const addDidFinishTransactionListener = (listener) =>
@@ -2525,11 +2437,12 @@ const createStore = () => {
2525
2437
  };
2526
2438
  const getListenerStats = () => ({
2527
2439
  tables: pairCollSize2(tablesListeners),
2528
- tableIds: pair2CollSize2(tableIdsListeners),
2440
+ tableIds: pairCollSize2(tableIdsListeners),
2529
2441
  table: pairCollSize2(tableListeners),
2530
- rowIds: pair2CollSize2(rowIdsListeners),
2442
+ rowIds: pairCollSize2(rowIdsListeners),
2443
+ sortedRowIds: pairCollSize2(sortedRowIdsListeners),
2531
2444
  row: pairCollSize2(rowListeners, collSize3),
2532
- cellIds: pair2CollSize2(cellIdsListeners, collSize3),
2445
+ cellIds: pairCollSize2(cellIdsListeners, collSize3),
2533
2446
  cell: pairCollSize2(cellListeners, collSize4),
2534
2447
  invalidCell: pairCollSize2(invalidCellListeners, collSize4),
2535
2448
  transaction: pairCollSize2(finishTransactionListeners),
@@ -2539,6 +2452,7 @@ const createStore = () => {
2539
2452
  getTableIds,
2540
2453
  getTable,
2541
2454
  getRowIds,
2455
+ getSortedRowIds,
2542
2456
  getRow,
2543
2457
  getCellIds,
2544
2458
  getCell,
@@ -2567,14 +2481,7 @@ const createStore = () => {
2567
2481
  forEachTable,
2568
2482
  forEachRow,
2569
2483
  forEachCell,
2570
- addTablesListener,
2571
- addTableIdsListener,
2572
- addTableListener,
2573
- addRowIdsListener,
2574
- addRowListener,
2575
- addCellIdsListener,
2576
- addCellListener,
2577
- addInvalidCellListener,
2484
+ addSortedRowIdsListener,
2578
2485
  addWillFinishTransactionListener,
2579
2486
  addDidFinishTransactionListener,
2580
2487
  callListener,
@@ -2582,6 +2489,26 @@ const createStore = () => {
2582
2489
  getListenerStats,
2583
2490
  createStore,
2584
2491
  };
2492
+ objForEach(
2493
+ {
2494
+ [TABLES]: [0, tablesListeners],
2495
+ [TABLE_IDS]: [0, tableIdsListeners],
2496
+ [TABLE]: [1, tableListeners],
2497
+ [ROW_IDS]: [1, rowIdsListeners],
2498
+ [ROW]: [2, rowListeners],
2499
+ [CELL_IDS]: [2, cellIdsListeners],
2500
+ [CELL]: [3, cellListeners],
2501
+ InvalidCell: [3, invalidCellListeners],
2502
+ },
2503
+ ([argumentCount, idSetNode], listenable) => {
2504
+ store[ADD + listenable + LISTENER] = (...args) =>
2505
+ addListener(
2506
+ args[argumentCount],
2507
+ idSetNode[args[argumentCount + 1] ? 1 : 0],
2508
+ argumentCount > 0 ? arraySlice(args, 0, argumentCount) : void 0,
2509
+ );
2510
+ },
2511
+ );
2585
2512
  return objFreeze(store);
2586
2513
  };
2587
2514
 
@@ -2598,4 +2525,5 @@ export {
2598
2525
  createSessionPersister,
2599
2526
  createStore,
2600
2527
  defaultSorter,
2528
+ id,
2601
2529
  };