tinybase 2.0.0-beta.2 → 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.
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.js +1 -4
- package/lib/debug/indexes.js +1 -3
- package/lib/debug/metrics.js +1 -4
- package/lib/debug/queries.d.ts +61 -296
- package/lib/debug/queries.js +59 -201
- package/lib/debug/relationships.js +1 -4
- package/lib/debug/store.d.ts +112 -90
- package/lib/debug/store.js +90 -149
- package/lib/debug/tinybase.js +130 -333
- package/lib/debug/ui-react.d.ts +81 -81
- package/lib/debug/ui-react.js +138 -173
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/queries.d.ts +61 -296
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +112 -90
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +81 -81
- 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 -1
- 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 +9 -9
- package/readme.md +2 -2
package/lib/debug/tinybase.js
CHANGED
|
@@ -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);
|
|
@@ -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,
|
|
353
|
+
return [addListener, callListeners, delListener, callListener];
|
|
344
354
|
};
|
|
345
355
|
|
|
346
356
|
const object = Object;
|
|
@@ -1098,25 +1108,22 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1098
1108
|
addStoreListeners,
|
|
1099
1109
|
delStoreListeners,
|
|
1100
1110
|
] = getDefinableFunctions(store, () => true, getUndefined);
|
|
1101
|
-
const
|
|
1102
|
-
const preStore2 = createStore();
|
|
1111
|
+
const preStore = createStore();
|
|
1103
1112
|
const resultStore = createStore();
|
|
1104
1113
|
const preStoreListenerIds = mapNew();
|
|
1105
|
-
const addPreStoreListener = (
|
|
1114
|
+
const addPreStoreListener = (preStore2, queryId, ...listenerIds) =>
|
|
1106
1115
|
arrayForEach(listenerIds, (listenerId) =>
|
|
1107
1116
|
setAdd(
|
|
1108
1117
|
mapEnsure(
|
|
1109
1118
|
mapEnsure(preStoreListenerIds, queryId, mapNew),
|
|
1110
|
-
|
|
1119
|
+
preStore2,
|
|
1111
1120
|
setNew,
|
|
1112
1121
|
),
|
|
1113
1122
|
listenerId,
|
|
1114
1123
|
),
|
|
1115
1124
|
);
|
|
1116
1125
|
const cleanPreStores = (queryId) =>
|
|
1117
|
-
arrayForEach([resultStore,
|
|
1118
|
-
store2.delTable(queryId),
|
|
1119
|
-
);
|
|
1126
|
+
arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
|
|
1120
1127
|
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
1121
1128
|
addPreStoreListener(
|
|
1122
1129
|
fromStore,
|
|
@@ -1129,13 +1136,11 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1129
1136
|
const setQueryDefinition = (queryId, tableId, build) => {
|
|
1130
1137
|
setDefinition(queryId, tableId);
|
|
1131
1138
|
cleanPreStores(queryId);
|
|
1132
|
-
let offsetLimit;
|
|
1133
1139
|
const selectEntries = [];
|
|
1134
1140
|
const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
|
|
1135
1141
|
const wheres = [];
|
|
1136
1142
|
const groupEntries = [];
|
|
1137
1143
|
const havings = [];
|
|
1138
|
-
const orders = [];
|
|
1139
1144
|
const select = (arg1, arg2) => {
|
|
1140
1145
|
const selectEntry = isFunction(arg1)
|
|
1141
1146
|
? [arrayLength(selectEntries) + EMPTY_STRING, arg1]
|
|
@@ -1201,17 +1206,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1201
1206
|
: (getSelectedOrGroupedCell) =>
|
|
1202
1207
|
getSelectedOrGroupedCell(arg1) === arg2,
|
|
1203
1208
|
);
|
|
1204
|
-
|
|
1205
|
-
arrayPush(orders, [
|
|
1206
|
-
isFunction(arg1)
|
|
1207
|
-
? arg1
|
|
1208
|
-
: (getSelectedOrGroupedCell) => getSelectedOrGroupedCell(arg1) ?? 0,
|
|
1209
|
-
descending,
|
|
1210
|
-
]);
|
|
1211
|
-
const limit = (arg1, arg2) => {
|
|
1212
|
-
offsetLimit = isUndefined(arg2) ? [0, arg1] : [arg1, arg2];
|
|
1213
|
-
};
|
|
1214
|
-
build({select, join, where, group, having, order, limit});
|
|
1209
|
+
build({select, join, where, group, having});
|
|
1215
1210
|
const selects = mapNew(selectEntries);
|
|
1216
1211
|
if (collIsEmpty(selects)) {
|
|
1217
1212
|
return queries;
|
|
@@ -1223,95 +1218,11 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1223
1218
|
),
|
|
1224
1219
|
);
|
|
1225
1220
|
const groups = mapNew(groupEntries);
|
|
1226
|
-
let selectJoinWhereStore =
|
|
1227
|
-
let groupHavingStore = preStore2;
|
|
1228
|
-
if (arrayIsEmpty(orders) && isUndefined(offsetLimit)) {
|
|
1229
|
-
groupHavingStore = resultStore;
|
|
1230
|
-
} else {
|
|
1231
|
-
synchronizeTransactions(queryId, groupHavingStore, resultStore);
|
|
1232
|
-
const groupRowIdSorter = (rowId1, rowId2) => {
|
|
1233
|
-
const sortKeys1 = mapGet(sortKeysByGroupRowId, rowId1) ?? [];
|
|
1234
|
-
const sortKeys2 = mapGet(sortKeysByGroupRowId, rowId2) ?? [];
|
|
1235
|
-
const orderIndex = orders.findIndex(
|
|
1236
|
-
(_order, index) => sortKeys1[index] !== sortKeys2[index],
|
|
1237
|
-
);
|
|
1238
|
-
return orderIndex < 0
|
|
1239
|
-
? 0
|
|
1240
|
-
: defaultSorter(sortKeys1[orderIndex], sortKeys2[orderIndex]) *
|
|
1241
|
-
(orders[orderIndex][1] ? -1 : 1);
|
|
1242
|
-
};
|
|
1243
|
-
const sortKeysByGroupRowId = mapNew();
|
|
1244
|
-
const sortedGroupRowIds = mapNew();
|
|
1245
|
-
addPreStoreListener(
|
|
1246
|
-
groupHavingStore,
|
|
1247
|
-
queryId,
|
|
1248
|
-
arrayIsEmpty(orders)
|
|
1249
|
-
? groupHavingStore.addRowIdsListener(queryId, () =>
|
|
1250
|
-
collClear(sortedGroupRowIds),
|
|
1251
|
-
)
|
|
1252
|
-
: groupHavingStore.addRowListener(
|
|
1253
|
-
queryId,
|
|
1254
|
-
null,
|
|
1255
|
-
(_store, _tableId, groupRowId) => {
|
|
1256
|
-
let newSortKeys = null;
|
|
1257
|
-
if (groupHavingStore.hasRow(queryId, groupRowId)) {
|
|
1258
|
-
const oldSortKeys =
|
|
1259
|
-
mapGet(sortKeysByGroupRowId, groupRowId) ?? [];
|
|
1260
|
-
const groupRow = groupHavingStore.getRow(queryId, groupRowId);
|
|
1261
|
-
const getCell = (getSelectedOrGroupedCell) =>
|
|
1262
|
-
groupRow[getSelectedOrGroupedCell];
|
|
1263
|
-
newSortKeys = arrayMap(orders, ([getSortKey]) =>
|
|
1264
|
-
getSortKey(getCell, groupRowId),
|
|
1265
|
-
);
|
|
1266
|
-
if (arrayIsEqual(oldSortKeys, newSortKeys)) {
|
|
1267
|
-
if (mapGet(sortedGroupRowIds, groupRowId)) {
|
|
1268
|
-
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
1269
|
-
}
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
mapSet(sortKeysByGroupRowId, groupRowId, newSortKeys);
|
|
1274
|
-
collClear(sortedGroupRowIds);
|
|
1275
|
-
},
|
|
1276
|
-
),
|
|
1277
|
-
groupHavingStore.addTableListener(queryId, () => {
|
|
1278
|
-
if (collIsEmpty(sortedGroupRowIds)) {
|
|
1279
|
-
resultStore.delTable(queryId);
|
|
1280
|
-
if (groupHavingStore.hasTable(queryId)) {
|
|
1281
|
-
const groupTable = groupHavingStore.getTable(queryId);
|
|
1282
|
-
arrayForEach(
|
|
1283
|
-
arraySort(objIds(groupTable), groupRowIdSorter),
|
|
1284
|
-
(id) => mapSet(sortedGroupRowIds, id, 0),
|
|
1285
|
-
);
|
|
1286
|
-
arrayForEach(
|
|
1287
|
-
ifNotUndefined(
|
|
1288
|
-
offsetLimit,
|
|
1289
|
-
([offset, limit2]) =>
|
|
1290
|
-
arraySlice(
|
|
1291
|
-
mapKeys(sortedGroupRowIds),
|
|
1292
|
-
offset,
|
|
1293
|
-
offset + limit2,
|
|
1294
|
-
),
|
|
1295
|
-
() => mapKeys(sortedGroupRowIds),
|
|
1296
|
-
),
|
|
1297
|
-
(groupRowId) => {
|
|
1298
|
-
resultStore.setRow(
|
|
1299
|
-
queryId,
|
|
1300
|
-
groupRowId,
|
|
1301
|
-
groupTable[groupRowId],
|
|
1302
|
-
);
|
|
1303
|
-
mapSet(sortedGroupRowIds, groupRowId, 1);
|
|
1304
|
-
},
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
}),
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1221
|
+
let selectJoinWhereStore = preStore;
|
|
1311
1222
|
if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
|
|
1312
|
-
selectJoinWhereStore =
|
|
1223
|
+
selectJoinWhereStore = resultStore;
|
|
1313
1224
|
} else {
|
|
1314
|
-
synchronizeTransactions(queryId, selectJoinWhereStore,
|
|
1225
|
+
synchronizeTransactions(queryId, selectJoinWhereStore, resultStore);
|
|
1315
1226
|
const groupedSelectedCellIds = mapNew();
|
|
1316
1227
|
mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
|
|
1317
1228
|
setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
|
|
@@ -1373,8 +1284,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1373
1284
|
!arrayEvery(havings, (having2) =>
|
|
1374
1285
|
having2((cellId) => groupRow[cellId]),
|
|
1375
1286
|
)
|
|
1376
|
-
?
|
|
1377
|
-
:
|
|
1287
|
+
? resultStore.delRow
|
|
1288
|
+
: resultStore.setRow)(queryId, groupRowId, groupRow);
|
|
1378
1289
|
},
|
|
1379
1290
|
);
|
|
1380
1291
|
addPreStoreListener(
|
|
@@ -1421,7 +1332,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1421
1332
|
([, selectedRowIds, groupRowId]) => {
|
|
1422
1333
|
collDel(selectedRowIds, selectedRowId);
|
|
1423
1334
|
if (collIsEmpty(selectedRowIds)) {
|
|
1424
|
-
|
|
1335
|
+
resultStore.delRow(queryId, groupRowId);
|
|
1425
1336
|
return 1;
|
|
1426
1337
|
}
|
|
1427
1338
|
},
|
|
@@ -1451,7 +1362,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1451
1362
|
return [
|
|
1452
1363
|
mapNew(),
|
|
1453
1364
|
setNew(),
|
|
1454
|
-
|
|
1365
|
+
resultStore.addRow(queryId, groupRow, 1),
|
|
1455
1366
|
groupRow,
|
|
1456
1367
|
];
|
|
1457
1368
|
},
|
|
@@ -1558,68 +1469,15 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1558
1469
|
return queries;
|
|
1559
1470
|
};
|
|
1560
1471
|
const delQueryDefinition = (queryId) => {
|
|
1561
|
-
mapForEach(mapGet(preStoreListenerIds, queryId), (
|
|
1472
|
+
mapForEach(mapGet(preStoreListenerIds, queryId), (preStore2, listenerIds) =>
|
|
1562
1473
|
collForEach(listenerIds, (listenerId) =>
|
|
1563
|
-
|
|
1474
|
+
preStore2.delListener(listenerId),
|
|
1564
1475
|
),
|
|
1565
1476
|
);
|
|
1566
1477
|
cleanPreStores(queryId);
|
|
1567
1478
|
delDefinition(queryId);
|
|
1568
1479
|
return queries;
|
|
1569
1480
|
};
|
|
1570
|
-
const getResultTable = (queryId) => resultStore.getTable(queryId);
|
|
1571
|
-
const getResultRowIds = (queryId) => resultStore.getRowIds(queryId);
|
|
1572
|
-
const getResultSortedRowIds = (queryId, cellId, descending) =>
|
|
1573
|
-
resultStore.getSortedRowIds(queryId, cellId, descending);
|
|
1574
|
-
const getResultRow = (queryId, rowId) => resultStore.getRow(queryId, rowId);
|
|
1575
|
-
const getResultCellIds = (queryId, rowId) =>
|
|
1576
|
-
resultStore.getCellIds(queryId, rowId);
|
|
1577
|
-
const getResultCell = (queryId, rowId, cellId) =>
|
|
1578
|
-
resultStore.getCell(queryId, rowId, cellId);
|
|
1579
|
-
const hasResultTable = (queryId) => resultStore.hasTable(queryId);
|
|
1580
|
-
const hasResultRow = (queryId, rowId) => resultStore.hasRow(queryId, rowId);
|
|
1581
|
-
const hasResultCell = (queryId, rowId, cellId) =>
|
|
1582
|
-
resultStore.hasCell(queryId, rowId, cellId);
|
|
1583
|
-
const forEachResultTable = (tableCallback) =>
|
|
1584
|
-
resultStore.forEachTable(tableCallback);
|
|
1585
|
-
const forEachResultRow = (queryId, rowCallback) =>
|
|
1586
|
-
resultStore.forEachRow(queryId, rowCallback);
|
|
1587
|
-
const forEachResultCell = (queryId, rowId, cellCallback) =>
|
|
1588
|
-
resultStore.forEachCell(queryId, rowId, cellCallback);
|
|
1589
|
-
const addResultTableListener = (queryId, listener) =>
|
|
1590
|
-
resultStore.addTableListener(queryId, (_store, ...args) =>
|
|
1591
|
-
listener(queries, ...args),
|
|
1592
|
-
);
|
|
1593
|
-
const addResultRowIdsListener = (queryId, listener, trackReorder) =>
|
|
1594
|
-
resultStore.addRowIdsListener(
|
|
1595
|
-
queryId,
|
|
1596
|
-
(_store, ...args) => listener(queries, ...args),
|
|
1597
|
-
trackReorder,
|
|
1598
|
-
);
|
|
1599
|
-
const addResultSortedRowIdsListener = (
|
|
1600
|
-
queryId,
|
|
1601
|
-
cellId,
|
|
1602
|
-
descending,
|
|
1603
|
-
listener,
|
|
1604
|
-
) =>
|
|
1605
|
-
resultStore.addSortedRowIdsListener(
|
|
1606
|
-
queryId,
|
|
1607
|
-
cellId,
|
|
1608
|
-
descending,
|
|
1609
|
-
(_store, ...args) => listener(queries, ...args),
|
|
1610
|
-
);
|
|
1611
|
-
const addResultRowListener = (queryId, rowId, listener) =>
|
|
1612
|
-
resultStore.addRowListener(queryId, rowId, (_store, ...args) =>
|
|
1613
|
-
listener(queries, ...args),
|
|
1614
|
-
);
|
|
1615
|
-
const addResultCellIdsListener = (queryId, rowId, listener) =>
|
|
1616
|
-
resultStore.addCellIdsListener(queryId, rowId, (_store, ...args) =>
|
|
1617
|
-
listener(queries, ...args),
|
|
1618
|
-
);
|
|
1619
|
-
const addResultCellListener = (queryId, rowId, cellId, listener) =>
|
|
1620
|
-
resultStore.addCellListener(queryId, rowId, cellId, (_store, ...args) =>
|
|
1621
|
-
listener(queries, ...args),
|
|
1622
|
-
);
|
|
1623
1481
|
const delListener = (listenerId) => {
|
|
1624
1482
|
resultStore.delListener(listenerId);
|
|
1625
1483
|
return queries;
|
|
@@ -1641,28 +1499,34 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1641
1499
|
forEachQuery,
|
|
1642
1500
|
hasQuery,
|
|
1643
1501
|
getTableId,
|
|
1644
|
-
getResultTable,
|
|
1645
|
-
getResultRowIds,
|
|
1646
|
-
getResultSortedRowIds,
|
|
1647
|
-
getResultRow,
|
|
1648
|
-
getResultCellIds,
|
|
1649
|
-
getResultCell,
|
|
1650
|
-
hasResultTable,
|
|
1651
|
-
hasResultRow,
|
|
1652
|
-
hasResultCell,
|
|
1653
|
-
forEachResultTable,
|
|
1654
|
-
forEachResultRow,
|
|
1655
|
-
forEachResultCell,
|
|
1656
|
-
addResultTableListener,
|
|
1657
|
-
addResultRowIdsListener,
|
|
1658
|
-
addResultSortedRowIdsListener,
|
|
1659
|
-
addResultRowListener,
|
|
1660
|
-
addResultCellIdsListener,
|
|
1661
|
-
addResultCellListener,
|
|
1662
1502
|
delListener,
|
|
1663
1503
|
destroy,
|
|
1664
1504
|
getListenerStats,
|
|
1665
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
|
+
);
|
|
1666
1530
|
return objFreeze(queries);
|
|
1667
1531
|
});
|
|
1668
1532
|
|
|
@@ -1855,11 +1719,7 @@ const createRelationships = getCreateFunction((store) => {
|
|
|
1855
1719
|
|
|
1856
1720
|
const pairNew = (value) => [value, value];
|
|
1857
1721
|
const pairCollSize2 = (pair, func = collSize2) => func(pair[0]) + func(pair[1]);
|
|
1858
|
-
const pairCollIsEmpty = (pair) => pairCollSize2(pair) == 0;
|
|
1859
1722
|
const pairNewMap = () => [mapNew(), mapNew()];
|
|
1860
|
-
const pair2CollSize2 = (pair2, func = collSize2) =>
|
|
1861
|
-
pairCollSize2(pair2[0], func) + pairCollSize2(pair2[1], func);
|
|
1862
|
-
const pair2NewMap = () => [pairNewMap(), pairNewMap()];
|
|
1863
1723
|
|
|
1864
1724
|
const transformMap = (map, toBeLikeObject, setId, delId = mapSet) => {
|
|
1865
1725
|
const idsToDelete = arrayFilter(
|
|
@@ -1900,22 +1760,17 @@ const createStore = () => {
|
|
|
1900
1760
|
const schemaRowCache = mapNew();
|
|
1901
1761
|
const tablesMap = mapNew();
|
|
1902
1762
|
const tablesListeners = pairNewMap();
|
|
1903
|
-
const tableIdsListeners =
|
|
1763
|
+
const tableIdsListeners = pairNewMap();
|
|
1904
1764
|
const tableListeners = pairNewMap();
|
|
1905
|
-
const rowIdsListeners =
|
|
1765
|
+
const rowIdsListeners = pairNewMap();
|
|
1906
1766
|
const sortedRowIdsListeners = pairNewMap();
|
|
1907
1767
|
const rowListeners = pairNewMap();
|
|
1908
|
-
const cellIdsListeners =
|
|
1768
|
+
const cellIdsListeners = pairNewMap();
|
|
1909
1769
|
const cellListeners = pairNewMap();
|
|
1910
1770
|
const invalidCellListeners = pairNewMap();
|
|
1911
1771
|
const finishTransactionListeners = pairNewMap();
|
|
1912
|
-
const [
|
|
1913
|
-
|
|
1914
|
-
callListeners,
|
|
1915
|
-
delListenerImpl,
|
|
1916
|
-
hasListeners,
|
|
1917
|
-
callListenerImpl,
|
|
1918
|
-
] = getListenerFunctions(() => store);
|
|
1772
|
+
const [addListener, callListeners, delListenerImpl, callListenerImpl] =
|
|
1773
|
+
getListenerFunctions(() => store);
|
|
1919
1774
|
const validateSchema = (schema) =>
|
|
1920
1775
|
validate(schema, (tableSchema) =>
|
|
1921
1776
|
validate(tableSchema, (cellSchema) => {
|
|
@@ -2097,49 +1952,12 @@ const createStore = () => {
|
|
|
2097
1952
|
}
|
|
2098
1953
|
};
|
|
2099
1954
|
const tableIdsChanged = (tableId, added) =>
|
|
2100
|
-
idsChanged(
|
|
2101
|
-
collIsEmpty(changedTableIds)
|
|
2102
|
-
? mapSet(
|
|
2103
|
-
changedTableIds,
|
|
2104
|
-
null,
|
|
2105
|
-
hasListeners(tableIdsListeners[0][1]) ||
|
|
2106
|
-
hasListeners(tableIdsListeners[1][1])
|
|
2107
|
-
? getTableIds()
|
|
2108
|
-
: 0,
|
|
2109
|
-
)
|
|
2110
|
-
: changedTableIds,
|
|
2111
|
-
tableId,
|
|
2112
|
-
added,
|
|
2113
|
-
);
|
|
1955
|
+
idsChanged(changedTableIds, tableId, added);
|
|
2114
1956
|
const rowIdsChanged = (tableId, rowId, added) =>
|
|
2115
|
-
idsChanged(
|
|
2116
|
-
mapEnsure(changedRowIds, tableId, () =>
|
|
2117
|
-
mapNew([
|
|
2118
|
-
[
|
|
2119
|
-
null,
|
|
2120
|
-
hasListeners(rowIdsListeners[0][1], [tableId]) ||
|
|
2121
|
-
hasListeners(rowIdsListeners[1][1], [tableId])
|
|
2122
|
-
? getRowIds(tableId)
|
|
2123
|
-
: 0,
|
|
2124
|
-
],
|
|
2125
|
-
]),
|
|
2126
|
-
),
|
|
2127
|
-
rowId,
|
|
2128
|
-
added,
|
|
2129
|
-
);
|
|
1957
|
+
idsChanged(mapEnsure(changedRowIds, tableId, mapNew), rowId, added);
|
|
2130
1958
|
const cellIdsChanged = (tableId, rowId, cellId, added) =>
|
|
2131
1959
|
idsChanged(
|
|
2132
|
-
mapEnsure(mapEnsure(changedCellIds, tableId, mapNew), rowId,
|
|
2133
|
-
mapNew([
|
|
2134
|
-
[
|
|
2135
|
-
null,
|
|
2136
|
-
hasListeners(cellIdsListeners[0][1], [tableId, rowId]) ||
|
|
2137
|
-
hasListeners(cellIdsListeners[1][1], [tableId, rowId])
|
|
2138
|
-
? getCellIds(tableId, rowId)
|
|
2139
|
-
: 0,
|
|
2140
|
-
],
|
|
2141
|
-
]),
|
|
2142
|
-
),
|
|
1960
|
+
mapEnsure(mapEnsure(changedCellIds, tableId, mapNew), rowId, mapNew),
|
|
2143
1961
|
cellId,
|
|
2144
1962
|
added,
|
|
2145
1963
|
);
|
|
@@ -2182,18 +2000,9 @@ const createStore = () => {
|
|
|
2182
2000
|
),
|
|
2183
2001
|
)
|
|
2184
2002
|
: 0;
|
|
2185
|
-
const callIdsListenersIfChanged = (listeners, changedIds,
|
|
2186
|
-
if (
|
|
2187
|
-
callListeners(listeners
|
|
2188
|
-
callListeners(listeners[1], ids);
|
|
2189
|
-
return 1;
|
|
2190
|
-
}
|
|
2191
|
-
if (
|
|
2192
|
-
!collIsEmpty(changedIds) &&
|
|
2193
|
-
mapGet(changedIds, null) != 0 &&
|
|
2194
|
-
!arrayIsEqual(mapGet(changedIds, null), getIds(...(ids ?? [])))
|
|
2195
|
-
) {
|
|
2196
|
-
callListeners(listeners[1], ids);
|
|
2003
|
+
const callIdsListenersIfChanged = (listeners, changedIds, ids) => {
|
|
2004
|
+
if (!collIsEmpty(changedIds)) {
|
|
2005
|
+
callListeners(listeners, ids);
|
|
2197
2006
|
return 1;
|
|
2198
2007
|
}
|
|
2199
2008
|
};
|
|
@@ -2202,10 +2011,10 @@ const createStore = () => {
|
|
|
2202
2011
|
sortedRowIdsListeners[mutator],
|
|
2203
2012
|
);
|
|
2204
2013
|
const emptyIdListeners =
|
|
2205
|
-
|
|
2206
|
-
|
|
2014
|
+
collIsEmpty(cellIdsListeners[mutator]) &&
|
|
2015
|
+
collIsEmpty(rowIdsListeners[mutator]) &&
|
|
2207
2016
|
emptySortedRowIdListeners &&
|
|
2208
|
-
|
|
2017
|
+
collIsEmpty(tableIdsListeners[mutator]);
|
|
2209
2018
|
const emptyOtherListeners =
|
|
2210
2019
|
collIsEmpty(cellListeners[mutator]) &&
|
|
2211
2020
|
collIsEmpty(rowListeners[mutator]) &&
|
|
@@ -2223,23 +2032,18 @@ const createStore = () => {
|
|
|
2223
2032
|
if (!emptyIdListeners) {
|
|
2224
2033
|
collForEach(changes[2], (rowCellIds, tableId) =>
|
|
2225
2034
|
collForEach(rowCellIds, (changedIds, rowId) =>
|
|
2226
|
-
callIdsListenersIfChanged(
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
[tableId, rowId],
|
|
2231
|
-
),
|
|
2035
|
+
callIdsListenersIfChanged(cellIdsListeners[mutator], changedIds, [
|
|
2036
|
+
tableId,
|
|
2037
|
+
rowId,
|
|
2038
|
+
]),
|
|
2232
2039
|
),
|
|
2233
2040
|
);
|
|
2234
2041
|
const calledSortableTableIds = setNew();
|
|
2235
2042
|
collForEach(changes[1], (changedIds, tableId) => {
|
|
2236
2043
|
if (
|
|
2237
|
-
callIdsListenersIfChanged(
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
getRowIds,
|
|
2241
|
-
[tableId],
|
|
2242
|
-
) &&
|
|
2044
|
+
callIdsListenersIfChanged(rowIdsListeners[mutator], changedIds, [
|
|
2045
|
+
tableId,
|
|
2046
|
+
]) &&
|
|
2243
2047
|
!emptySortedRowIdListeners
|
|
2244
2048
|
) {
|
|
2245
2049
|
callListeners(sortedRowIdsListeners[mutator], [tableId, null]);
|
|
@@ -2266,11 +2070,7 @@ const createStore = () => {
|
|
|
2266
2070
|
}
|
|
2267
2071
|
});
|
|
2268
2072
|
}
|
|
2269
|
-
callIdsListenersIfChanged(
|
|
2270
|
-
tableIdsListeners[mutator],
|
|
2271
|
-
changes[0],
|
|
2272
|
-
getTableIds,
|
|
2273
|
-
);
|
|
2073
|
+
callIdsListenersIfChanged(tableIdsListeners[mutator], changes[0]);
|
|
2274
2074
|
}
|
|
2275
2075
|
if (!emptyOtherListeners) {
|
|
2276
2076
|
let tablesChanged;
|
|
@@ -2318,7 +2118,7 @@ const createStore = () => {
|
|
|
2318
2118
|
const getTable = (tableId) =>
|
|
2319
2119
|
mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
|
|
2320
2120
|
const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
|
|
2321
|
-
const getSortedRowIds = (tableId, cellId, descending) => {
|
|
2121
|
+
const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) => {
|
|
2322
2122
|
const cells = [];
|
|
2323
2123
|
mapForEach(mapGet(tablesMap, id(tableId)), (rowId, row) =>
|
|
2324
2124
|
arrayPush(cells, [
|
|
@@ -2327,10 +2127,14 @@ const createStore = () => {
|
|
|
2327
2127
|
]),
|
|
2328
2128
|
);
|
|
2329
2129
|
return arrayMap(
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
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,
|
|
2334
2138
|
),
|
|
2335
2139
|
([, rowId]) => rowId,
|
|
2336
2140
|
);
|
|
@@ -2575,67 +2379,48 @@ const createStore = () => {
|
|
|
2575
2379
|
);
|
|
2576
2380
|
const forEachCell = (tableId, rowId, cellCallback) =>
|
|
2577
2381
|
mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
|
|
2578
|
-
const addTablesListener = (listener, mutator) =>
|
|
2579
|
-
addListener(listener, tablesListeners[mutator ? 1 : 0]);
|
|
2580
|
-
const addTableIdsListener = (listener, trackReorder, mutator) =>
|
|
2581
|
-
addListener(
|
|
2582
|
-
listener,
|
|
2583
|
-
tableIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
|
|
2584
|
-
);
|
|
2585
|
-
const addTableListener = (tableId, listener, mutator) =>
|
|
2586
|
-
addListener(listener, tableListeners[mutator ? 1 : 0], [tableId]);
|
|
2587
|
-
const addRowIdsListener = (tableId, listener, trackReorder, mutator) =>
|
|
2588
|
-
addListener(
|
|
2589
|
-
listener,
|
|
2590
|
-
rowIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
|
|
2591
|
-
[tableId],
|
|
2592
|
-
);
|
|
2593
2382
|
const addSortedRowIdsListener = (
|
|
2594
2383
|
tableId,
|
|
2595
2384
|
cellId,
|
|
2596
2385
|
descending,
|
|
2386
|
+
offset,
|
|
2387
|
+
limit,
|
|
2597
2388
|
listener,
|
|
2598
2389
|
mutator,
|
|
2599
2390
|
) => {
|
|
2600
|
-
let sortedRowIds = getSortedRowIds(
|
|
2391
|
+
let sortedRowIds = getSortedRowIds(
|
|
2392
|
+
tableId,
|
|
2393
|
+
cellId,
|
|
2394
|
+
descending,
|
|
2395
|
+
offset,
|
|
2396
|
+
limit,
|
|
2397
|
+
);
|
|
2601
2398
|
return addListener(
|
|
2602
2399
|
() => {
|
|
2603
|
-
const newSortedRowIds = getSortedRowIds(
|
|
2400
|
+
const newSortedRowIds = getSortedRowIds(
|
|
2401
|
+
tableId,
|
|
2402
|
+
cellId,
|
|
2403
|
+
descending,
|
|
2404
|
+
offset,
|
|
2405
|
+
limit,
|
|
2406
|
+
);
|
|
2604
2407
|
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
2605
2408
|
sortedRowIds = newSortedRowIds;
|
|
2606
|
-
listener(
|
|
2409
|
+
listener(
|
|
2410
|
+
store,
|
|
2411
|
+
tableId,
|
|
2412
|
+
cellId,
|
|
2413
|
+
descending,
|
|
2414
|
+
offset,
|
|
2415
|
+
limit,
|
|
2416
|
+
sortedRowIds,
|
|
2417
|
+
);
|
|
2607
2418
|
}
|
|
2608
2419
|
},
|
|
2609
2420
|
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
2610
2421
|
[tableId, cellId],
|
|
2611
2422
|
);
|
|
2612
2423
|
};
|
|
2613
|
-
const addRowListener = (tableId, rowId, listener, mutator) =>
|
|
2614
|
-
addListener(listener, rowListeners[mutator ? 1 : 0], [tableId, rowId]);
|
|
2615
|
-
const addCellIdsListener = (
|
|
2616
|
-
tableId,
|
|
2617
|
-
rowId,
|
|
2618
|
-
listener,
|
|
2619
|
-
trackReorder,
|
|
2620
|
-
mutator,
|
|
2621
|
-
) =>
|
|
2622
|
-
addListener(
|
|
2623
|
-
listener,
|
|
2624
|
-
cellIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
|
|
2625
|
-
[tableId, rowId],
|
|
2626
|
-
);
|
|
2627
|
-
const addCellListener = (tableId, rowId, cellId, listener, mutator) =>
|
|
2628
|
-
addListener(listener, cellListeners[mutator ? 1 : 0], [
|
|
2629
|
-
tableId,
|
|
2630
|
-
rowId,
|
|
2631
|
-
cellId,
|
|
2632
|
-
]);
|
|
2633
|
-
const addInvalidCellListener = (tableId, rowId, cellId, listener, mutator) =>
|
|
2634
|
-
addListener(listener, invalidCellListeners[mutator ? 1 : 0], [
|
|
2635
|
-
tableId,
|
|
2636
|
-
rowId,
|
|
2637
|
-
cellId,
|
|
2638
|
-
]);
|
|
2639
2424
|
const addWillFinishTransactionListener = (listener) =>
|
|
2640
2425
|
addListener(listener, finishTransactionListeners[0]);
|
|
2641
2426
|
const addDidFinishTransactionListener = (listener) =>
|
|
@@ -2652,12 +2437,12 @@ const createStore = () => {
|
|
|
2652
2437
|
};
|
|
2653
2438
|
const getListenerStats = () => ({
|
|
2654
2439
|
tables: pairCollSize2(tablesListeners),
|
|
2655
|
-
tableIds:
|
|
2440
|
+
tableIds: pairCollSize2(tableIdsListeners),
|
|
2656
2441
|
table: pairCollSize2(tableListeners),
|
|
2657
|
-
rowIds:
|
|
2442
|
+
rowIds: pairCollSize2(rowIdsListeners),
|
|
2658
2443
|
sortedRowIds: pairCollSize2(sortedRowIdsListeners),
|
|
2659
2444
|
row: pairCollSize2(rowListeners, collSize3),
|
|
2660
|
-
cellIds:
|
|
2445
|
+
cellIds: pairCollSize2(cellIdsListeners, collSize3),
|
|
2661
2446
|
cell: pairCollSize2(cellListeners, collSize4),
|
|
2662
2447
|
invalidCell: pairCollSize2(invalidCellListeners, collSize4),
|
|
2663
2448
|
transaction: pairCollSize2(finishTransactionListeners),
|
|
@@ -2696,15 +2481,7 @@ const createStore = () => {
|
|
|
2696
2481
|
forEachTable,
|
|
2697
2482
|
forEachRow,
|
|
2698
2483
|
forEachCell,
|
|
2699
|
-
addTablesListener,
|
|
2700
|
-
addTableIdsListener,
|
|
2701
|
-
addTableListener,
|
|
2702
|
-
addRowIdsListener,
|
|
2703
2484
|
addSortedRowIdsListener,
|
|
2704
|
-
addRowListener,
|
|
2705
|
-
addCellIdsListener,
|
|
2706
|
-
addCellListener,
|
|
2707
|
-
addInvalidCellListener,
|
|
2708
2485
|
addWillFinishTransactionListener,
|
|
2709
2486
|
addDidFinishTransactionListener,
|
|
2710
2487
|
callListener,
|
|
@@ -2712,6 +2489,26 @@ const createStore = () => {
|
|
|
2712
2489
|
getListenerStats,
|
|
2713
2490
|
createStore,
|
|
2714
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
|
+
);
|
|
2715
2512
|
return objFreeze(store);
|
|
2716
2513
|
};
|
|
2717
2514
|
|