tinybase 2.0.0-beta.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.d.ts +4 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/common.js +1 -1
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +4 -3
- package/lib/debug/checkpoints.js +12 -12
- package/lib/debug/common.js +4 -1
- package/lib/debug/indexes.d.ts +4 -2
- package/lib/debug/indexes.js +12 -12
- package/lib/debug/metrics.d.ts +1 -1
- package/lib/debug/metrics.js +12 -12
- package/lib/debug/persisters.d.ts +6 -0
- package/lib/debug/queries.d.ts +206 -9
- package/lib/debug/queries.js +29 -9
- package/lib/debug/relationships.d.ts +6 -5
- package/lib/debug/relationships.js +12 -12
- package/lib/debug/store.d.ts +287 -9
- package/lib/debug/store.js +210 -89
- package/lib/debug/tinybase.js +231 -97
- package/lib/debug/ui-react.d.ts +767 -5
- package/lib/debug/ui-react.js +158 -26
- package/lib/indexes.d.ts +4 -2
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +6 -0
- package/lib/queries.d.ts +206 -9
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +6 -5
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +287 -9
- 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 +767 -5
- 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/common.js +1 -1
- package/lib/umd/common.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 +25 -25
- package/readme.md +2 -2
package/lib/debug/store.js
CHANGED
|
@@ -13,7 +13,9 @@ const arrayEvery = (array, cb) => array.every(cb);
|
|
|
13
13
|
const arrayIsEqual = (array1, array2) =>
|
|
14
14
|
arrayLength(array1) === arrayLength(array2) &&
|
|
15
15
|
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
|
16
|
+
const arraySort = (array, sorter) => array.sort(sorter);
|
|
16
17
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
18
|
+
const arrayMap = (array, cb) => array.map(cb);
|
|
17
19
|
const arrayLength = (array) => array.length;
|
|
18
20
|
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
19
21
|
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
@@ -65,7 +67,7 @@ const mapSet = (map, key, value) =>
|
|
|
65
67
|
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
66
68
|
const mapEnsure = (map, key, getDefaultValue) => {
|
|
67
69
|
if (!collHas(map, key)) {
|
|
68
|
-
map
|
|
70
|
+
mapSet(map, key, getDefaultValue());
|
|
69
71
|
}
|
|
70
72
|
return mapGet(map, key);
|
|
71
73
|
};
|
|
@@ -125,32 +127,32 @@ const setNew = (entries) => new Set(entries);
|
|
|
125
127
|
const setAdd = (set, value) => set?.add(value);
|
|
126
128
|
|
|
127
129
|
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
128
|
-
const
|
|
129
|
-
const deep = (
|
|
130
|
+
const leaves = [];
|
|
131
|
+
const deep = (node, p) =>
|
|
130
132
|
p == arrayLength(path)
|
|
131
|
-
? arrayPush(
|
|
132
|
-
:
|
|
133
|
+
? arrayPush(leaves, node)
|
|
134
|
+
: path[p] === null
|
|
135
|
+
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
136
|
+
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
133
137
|
deep(deepIdSet, 0);
|
|
134
|
-
return
|
|
138
|
+
return leaves;
|
|
135
139
|
};
|
|
136
140
|
const getListenerFunctions = (getThing) => {
|
|
137
141
|
let thing;
|
|
138
142
|
let nextId = 0;
|
|
139
143
|
const listenerPool = [];
|
|
140
144
|
const allListeners = mapNew();
|
|
141
|
-
const addListener = (listener, idSetNode,
|
|
145
|
+
const addListener = (listener, idSetNode, path) => {
|
|
142
146
|
thing ??= getThing();
|
|
143
147
|
const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
|
|
144
|
-
mapSet(allListeners, id, [listener, idSetNode,
|
|
145
|
-
setAdd(visitTree(idSetNode,
|
|
148
|
+
mapSet(allListeners, id, [listener, idSetNode, path]);
|
|
149
|
+
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
|
146
150
|
return id;
|
|
147
151
|
};
|
|
148
152
|
const callListeners = (idSetNode, ids, ...extraArgs) =>
|
|
149
153
|
arrayForEach(getWildcardedLeaves(idSetNode, ids), (set) =>
|
|
150
154
|
collForEach(set, (id) =>
|
|
151
|
-
|
|
152
|
-
listener(thing, ...(ids ?? []), ...extraArgs),
|
|
153
|
-
),
|
|
155
|
+
mapGet(allListeners, id)[0](thing, ...(ids ?? []), ...extraArgs),
|
|
154
156
|
),
|
|
155
157
|
);
|
|
156
158
|
const delListener = (id) =>
|
|
@@ -198,16 +200,23 @@ const getCellType = (cell) => {
|
|
|
198
200
|
? type
|
|
199
201
|
: void 0;
|
|
200
202
|
};
|
|
203
|
+
const setOrDelCell = (store, tableId, rowId, cellId, cell) =>
|
|
204
|
+
isUndefined(cell)
|
|
205
|
+
? store.delCell(tableId, rowId, cellId, true)
|
|
206
|
+
: store.setCell(tableId, rowId, cellId, cell);
|
|
207
|
+
|
|
208
|
+
const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
|
|
209
|
+
const id = (key) => EMPTY_STRING + key;
|
|
201
210
|
|
|
202
211
|
const transformMap = (map, toBeLikeObject, setId, delId = mapSet) => {
|
|
203
212
|
const idsToDelete = arrayFilter(
|
|
204
213
|
mapKeys(map),
|
|
205
|
-
(
|
|
214
|
+
(id2) => !objHas(toBeLikeObject, id2),
|
|
206
215
|
);
|
|
207
|
-
arrayForEach(objIds(toBeLikeObject), (
|
|
208
|
-
setId(map,
|
|
216
|
+
arrayForEach(objIds(toBeLikeObject), (id2) =>
|
|
217
|
+
setId(map, id2, toBeLikeObject[id2]),
|
|
209
218
|
);
|
|
210
|
-
arrayForEach(idsToDelete, (
|
|
219
|
+
arrayForEach(idsToDelete, (id2) => delId(map, id2));
|
|
211
220
|
return map;
|
|
212
221
|
};
|
|
213
222
|
const validate = (obj, validateChild, onInvalidObj) => {
|
|
@@ -215,15 +224,15 @@ const validate = (obj, validateChild, onInvalidObj) => {
|
|
|
215
224
|
onInvalidObj?.();
|
|
216
225
|
return false;
|
|
217
226
|
}
|
|
218
|
-
objForEach(obj, (child,
|
|
219
|
-
if (!validateChild(child,
|
|
220
|
-
objDel(obj,
|
|
227
|
+
objForEach(obj, (child, id2) => {
|
|
228
|
+
if (!validateChild(child, id2)) {
|
|
229
|
+
objDel(obj, id2);
|
|
221
230
|
}
|
|
222
231
|
});
|
|
223
232
|
return !objIsEmpty(obj);
|
|
224
233
|
};
|
|
225
|
-
const idsChanged = (changedIds,
|
|
226
|
-
mapSet(changedIds,
|
|
234
|
+
const idsChanged = (changedIds, id2, added) =>
|
|
235
|
+
mapSet(changedIds, id2, mapGet(changedIds, id2) == -added ? void 0 : added);
|
|
227
236
|
const createStore = () => {
|
|
228
237
|
let hasSchema;
|
|
229
238
|
let cellsTouched;
|
|
@@ -241,6 +250,7 @@ const createStore = () => {
|
|
|
241
250
|
const tableIdsListeners = pair2NewMap();
|
|
242
251
|
const tableListeners = pairNewMap();
|
|
243
252
|
const rowIdsListeners = pair2NewMap();
|
|
253
|
+
const sortedRowIdsListeners = pairNewMap();
|
|
244
254
|
const rowListeners = pairNewMap();
|
|
245
255
|
const cellIdsListeners = pair2NewMap();
|
|
246
256
|
const cellListeners = pairNewMap();
|
|
@@ -257,7 +267,7 @@ const createStore = () => {
|
|
|
257
267
|
validate(schema, (tableSchema) =>
|
|
258
268
|
validate(tableSchema, (cellSchema) => {
|
|
259
269
|
if (
|
|
260
|
-
!validate(cellSchema, (_child,
|
|
270
|
+
!validate(cellSchema, (_child, id2) => arrayHas([TYPE, DEFAULT], id2))
|
|
261
271
|
) {
|
|
262
272
|
return false;
|
|
263
273
|
}
|
|
@@ -523,18 +533,25 @@ const createStore = () => {
|
|
|
523
533
|
if (collSize(changedIds) > 1) {
|
|
524
534
|
callListeners(listeners[0], ids);
|
|
525
535
|
callListeners(listeners[1], ids);
|
|
526
|
-
|
|
536
|
+
return 1;
|
|
537
|
+
}
|
|
538
|
+
if (
|
|
527
539
|
!collIsEmpty(changedIds) &&
|
|
528
540
|
mapGet(changedIds, null) != 0 &&
|
|
529
541
|
!arrayIsEqual(mapGet(changedIds, null), getIds(...(ids ?? [])))
|
|
530
542
|
) {
|
|
531
543
|
callListeners(listeners[1], ids);
|
|
544
|
+
return 1;
|
|
532
545
|
}
|
|
533
546
|
};
|
|
534
547
|
const callListenersForChanges = (mutator) => {
|
|
548
|
+
const emptySortedRowIdListeners = collIsEmpty(
|
|
549
|
+
sortedRowIdsListeners[mutator],
|
|
550
|
+
);
|
|
535
551
|
const emptyIdListeners =
|
|
536
552
|
pairCollIsEmpty(cellIdsListeners[mutator]) &&
|
|
537
553
|
pairCollIsEmpty(rowIdsListeners[mutator]) &&
|
|
554
|
+
emptySortedRowIdListeners &&
|
|
538
555
|
pairCollIsEmpty(tableIdsListeners[mutator]);
|
|
539
556
|
const emptyOtherListeners =
|
|
540
557
|
collIsEmpty(cellListeners[mutator]) &&
|
|
@@ -561,14 +578,41 @@ const createStore = () => {
|
|
|
561
578
|
),
|
|
562
579
|
),
|
|
563
580
|
);
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
581
|
+
const calledSortableTableIds = setNew();
|
|
582
|
+
collForEach(changes[1], (changedIds, tableId) => {
|
|
583
|
+
if (
|
|
584
|
+
callIdsListenersIfChanged(
|
|
585
|
+
rowIdsListeners[mutator],
|
|
586
|
+
changedIds,
|
|
587
|
+
getRowIds,
|
|
588
|
+
[tableId],
|
|
589
|
+
) &&
|
|
590
|
+
!emptySortedRowIdListeners
|
|
591
|
+
) {
|
|
592
|
+
callListeners(sortedRowIdsListeners[mutator], [tableId, null]);
|
|
593
|
+
setAdd(calledSortableTableIds, tableId);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
if (!emptySortedRowIdListeners) {
|
|
597
|
+
collForEach(changes[3], (rows, tableId) => {
|
|
598
|
+
if (!collHas(calledSortableTableIds, tableId)) {
|
|
599
|
+
const sortableCellIds = setNew();
|
|
600
|
+
collForEach(rows, (cells) =>
|
|
601
|
+
collForEach(cells, ([oldCell, newCell], cellId) =>
|
|
602
|
+
newCell !== oldCell
|
|
603
|
+
? setAdd(sortableCellIds, cellId)
|
|
604
|
+
: collDel(cells, cellId),
|
|
605
|
+
),
|
|
606
|
+
);
|
|
607
|
+
collForEach(sortableCellIds, (cellId) =>
|
|
608
|
+
callListeners(sortedRowIdsListeners[mutator], [
|
|
609
|
+
tableId,
|
|
610
|
+
cellId,
|
|
611
|
+
]),
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
572
616
|
callIdsListenersIfChanged(
|
|
573
617
|
tableIdsListeners[mutator],
|
|
574
618
|
changes[0],
|
|
@@ -611,26 +655,45 @@ const createStore = () => {
|
|
|
611
655
|
}
|
|
612
656
|
}
|
|
613
657
|
};
|
|
614
|
-
const fluentTransaction = (actions) => {
|
|
615
|
-
transaction(actions);
|
|
658
|
+
const fluentTransaction = (actions, ...args) => {
|
|
659
|
+
transaction(() => actions(...arrayMap(args, id)));
|
|
616
660
|
return store;
|
|
617
661
|
};
|
|
618
662
|
const getTables = () =>
|
|
619
663
|
mapToObj(tablesMap, (table) => mapToObj(table, mapToObj));
|
|
620
664
|
const getTableIds = () => mapKeys(tablesMap);
|
|
621
|
-
const getTable = (tableId) =>
|
|
622
|
-
|
|
665
|
+
const getTable = (tableId) =>
|
|
666
|
+
mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
|
|
667
|
+
const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
|
|
668
|
+
const getSortedRowIds = (tableId, cellId, descending) => {
|
|
669
|
+
const cells = [];
|
|
670
|
+
mapForEach(mapGet(tablesMap, id(tableId)), (rowId, row) =>
|
|
671
|
+
arrayPush(cells, [
|
|
672
|
+
isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
|
|
673
|
+
rowId,
|
|
674
|
+
]),
|
|
675
|
+
);
|
|
676
|
+
return arrayMap(
|
|
677
|
+
arraySort(
|
|
678
|
+
cells,
|
|
679
|
+
([cell1], [cell2]) =>
|
|
680
|
+
defaultSorter(cell1, cell2) * (descending ? -1 : 1),
|
|
681
|
+
),
|
|
682
|
+
([, rowId]) => rowId,
|
|
683
|
+
);
|
|
684
|
+
};
|
|
623
685
|
const getRow = (tableId, rowId) =>
|
|
624
|
-
mapToObj(mapGet(mapGet(tablesMap, tableId), rowId));
|
|
686
|
+
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
625
687
|
const getCellIds = (tableId, rowId) =>
|
|
626
|
-
mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
|
|
688
|
+
mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
627
689
|
const getCell = (tableId, rowId, cellId) =>
|
|
628
|
-
mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
|
|
690
|
+
mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
|
|
629
691
|
const hasTables = () => !collIsEmpty(tablesMap);
|
|
630
|
-
const hasTable = (tableId) => collHas(tablesMap, tableId);
|
|
631
|
-
const hasRow = (tableId, rowId) =>
|
|
692
|
+
const hasTable = (tableId) => collHas(tablesMap, id(tableId));
|
|
693
|
+
const hasRow = (tableId, rowId) =>
|
|
694
|
+
collHas(mapGet(tablesMap, id(tableId)), id(rowId));
|
|
632
695
|
const hasCell = (tableId, rowId, cellId) =>
|
|
633
|
-
collHas(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
|
|
696
|
+
collHas(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
|
|
634
697
|
const getJson = () => jsonString(tablesMap);
|
|
635
698
|
const getSchemaJson = () => jsonString(schemaMap);
|
|
636
699
|
const setTables = (tables) =>
|
|
@@ -638,17 +701,28 @@ const createStore = () => {
|
|
|
638
701
|
validateTables(tables) ? setValidTables(tables) : 0,
|
|
639
702
|
);
|
|
640
703
|
const setTable = (tableId, table) =>
|
|
641
|
-
fluentTransaction(
|
|
642
|
-
|
|
704
|
+
fluentTransaction(
|
|
705
|
+
(tableId2) =>
|
|
706
|
+
validateTable(table, tableId2) ? setValidTable(tableId2, table) : 0,
|
|
707
|
+
tableId,
|
|
643
708
|
);
|
|
644
709
|
const setRow = (tableId, rowId, row) =>
|
|
645
|
-
fluentTransaction(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
710
|
+
fluentTransaction(
|
|
711
|
+
(tableId2, rowId2) =>
|
|
712
|
+
validateRow(id(tableId2), id(rowId2), row)
|
|
713
|
+
? setValidRow(
|
|
714
|
+
id(tableId2),
|
|
715
|
+
getOrCreateTable(id(tableId2)),
|
|
716
|
+
id(rowId2),
|
|
717
|
+
row,
|
|
718
|
+
)
|
|
719
|
+
: 0,
|
|
720
|
+
tableId,
|
|
721
|
+
rowId,
|
|
649
722
|
);
|
|
650
723
|
const addRow = (tableId, row, forceId) =>
|
|
651
724
|
transaction(() => {
|
|
725
|
+
tableId = id(tableId);
|
|
652
726
|
const isValidRow = validateRow(tableId, void 0, row);
|
|
653
727
|
const rowId =
|
|
654
728
|
isValidRow || forceId
|
|
@@ -660,32 +734,40 @@ const createStore = () => {
|
|
|
660
734
|
return rowId;
|
|
661
735
|
});
|
|
662
736
|
const setPartialRow = (tableId, rowId, partialRow) =>
|
|
663
|
-
fluentTransaction(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
737
|
+
fluentTransaction(
|
|
738
|
+
(tableId2, rowId2) => {
|
|
739
|
+
if (validateRow(tableId2, rowId2, partialRow, 1)) {
|
|
740
|
+
const table = getOrCreateTable(tableId2);
|
|
741
|
+
objForEach(partialRow, (cell, cellId) =>
|
|
742
|
+
setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
tableId,
|
|
747
|
+
rowId,
|
|
748
|
+
);
|
|
671
749
|
const setCell = (tableId, rowId, cellId, cell) =>
|
|
672
|
-
fluentTransaction(
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
(validCell) =>
|
|
681
|
-
setCellIntoDefaultRow(
|
|
682
|
-
tableId,
|
|
683
|
-
getOrCreateTable(tableId),
|
|
684
|
-
rowId,
|
|
685
|
-
cellId,
|
|
686
|
-
validCell,
|
|
750
|
+
fluentTransaction(
|
|
751
|
+
(tableId2, rowId2, cellId2) =>
|
|
752
|
+
ifNotUndefined(
|
|
753
|
+
getValidatedCell(
|
|
754
|
+
tableId2,
|
|
755
|
+
rowId2,
|
|
756
|
+
cellId2,
|
|
757
|
+
isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
|
|
687
758
|
),
|
|
688
|
-
|
|
759
|
+
(validCell) =>
|
|
760
|
+
setCellIntoDefaultRow(
|
|
761
|
+
tableId2,
|
|
762
|
+
getOrCreateTable(tableId2),
|
|
763
|
+
rowId2,
|
|
764
|
+
cellId2,
|
|
765
|
+
validCell,
|
|
766
|
+
),
|
|
767
|
+
),
|
|
768
|
+
tableId,
|
|
769
|
+
rowId,
|
|
770
|
+
cellId,
|
|
689
771
|
);
|
|
690
772
|
const setJson = (json) => {
|
|
691
773
|
try {
|
|
@@ -706,24 +788,42 @@ const createStore = () => {
|
|
|
706
788
|
});
|
|
707
789
|
const delTables = () => fluentTransaction(() => setValidTables({}));
|
|
708
790
|
const delTable = (tableId) =>
|
|
709
|
-
fluentTransaction(
|
|
710
|
-
|
|
791
|
+
fluentTransaction(
|
|
792
|
+
(tableId2) =>
|
|
793
|
+
collHas(tablesMap, tableId2) ? delValidTable(tableId2) : 0,
|
|
794
|
+
tableId,
|
|
711
795
|
);
|
|
712
796
|
const delRow = (tableId, rowId) =>
|
|
713
|
-
fluentTransaction(
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
797
|
+
fluentTransaction(
|
|
798
|
+
(tableId2, rowId2) =>
|
|
799
|
+
ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
|
|
800
|
+
collHas(tableMap, rowId2)
|
|
801
|
+
? delValidRow(tableId2, tableMap, rowId2)
|
|
802
|
+
: 0,
|
|
803
|
+
),
|
|
804
|
+
tableId,
|
|
805
|
+
rowId,
|
|
717
806
|
);
|
|
718
807
|
const delCell = (tableId, rowId, cellId, forceDel) =>
|
|
719
|
-
fluentTransaction(
|
|
720
|
-
|
|
721
|
-
ifNotUndefined(mapGet(
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
808
|
+
fluentTransaction(
|
|
809
|
+
(tableId2, rowId2, cellId2) =>
|
|
810
|
+
ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
|
|
811
|
+
ifNotUndefined(mapGet(tableMap, rowId2), (rowMap) =>
|
|
812
|
+
collHas(rowMap, cellId2)
|
|
813
|
+
? delValidCell(
|
|
814
|
+
tableId2,
|
|
815
|
+
tableMap,
|
|
816
|
+
rowId2,
|
|
817
|
+
rowMap,
|
|
818
|
+
cellId2,
|
|
819
|
+
forceDel,
|
|
820
|
+
)
|
|
821
|
+
: 0,
|
|
822
|
+
),
|
|
725
823
|
),
|
|
726
|
-
|
|
824
|
+
tableId,
|
|
825
|
+
rowId,
|
|
826
|
+
cellId,
|
|
727
827
|
);
|
|
728
828
|
const delSchema = () =>
|
|
729
829
|
fluentTransaction(() => {
|
|
@@ -778,9 +878,7 @@ const createStore = () => {
|
|
|
778
878
|
collForEach(changedCells, (table, tableId) =>
|
|
779
879
|
collForEach(table, (row, rowId) =>
|
|
780
880
|
collForEach(row, ([oldCell], cellId) =>
|
|
781
|
-
|
|
782
|
-
? delCell(tableId, rowId, cellId, true)
|
|
783
|
-
: setCell(tableId, rowId, cellId, oldCell),
|
|
881
|
+
setOrDelCell(store, tableId, rowId, cellId, oldCell),
|
|
784
882
|
),
|
|
785
883
|
),
|
|
786
884
|
);
|
|
@@ -819,11 +917,11 @@ const createStore = () => {
|
|
|
819
917
|
),
|
|
820
918
|
);
|
|
821
919
|
const forEachRow = (tableId, rowCallback) =>
|
|
822
|
-
collForEach(mapGet(tablesMap, tableId), (rowMap, rowId) =>
|
|
920
|
+
collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
|
|
823
921
|
rowCallback(rowId, (cellCallback) => mapForEach(rowMap, cellCallback)),
|
|
824
922
|
);
|
|
825
923
|
const forEachCell = (tableId, rowId, cellCallback) =>
|
|
826
|
-
mapForEach(mapGet(mapGet(tablesMap, tableId), rowId), cellCallback);
|
|
924
|
+
mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
|
|
827
925
|
const addTablesListener = (listener, mutator) =>
|
|
828
926
|
addListener(listener, tablesListeners[mutator ? 1 : 0]);
|
|
829
927
|
const addTableIdsListener = (listener, trackReorder, mutator) =>
|
|
@@ -839,6 +937,26 @@ const createStore = () => {
|
|
|
839
937
|
rowIdsListeners[mutator ? 1 : 0][trackReorder ? 1 : 0],
|
|
840
938
|
[tableId],
|
|
841
939
|
);
|
|
940
|
+
const addSortedRowIdsListener = (
|
|
941
|
+
tableId,
|
|
942
|
+
cellId,
|
|
943
|
+
descending,
|
|
944
|
+
listener,
|
|
945
|
+
mutator,
|
|
946
|
+
) => {
|
|
947
|
+
let sortedRowIds = getSortedRowIds(tableId, cellId, descending);
|
|
948
|
+
return addListener(
|
|
949
|
+
() => {
|
|
950
|
+
const newSortedRowIds = getSortedRowIds(tableId, cellId, descending);
|
|
951
|
+
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
952
|
+
sortedRowIds = newSortedRowIds;
|
|
953
|
+
listener(store, tableId, cellId, descending, sortedRowIds);
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
957
|
+
[tableId, cellId],
|
|
958
|
+
);
|
|
959
|
+
};
|
|
842
960
|
const addRowListener = (tableId, rowId, listener, mutator) =>
|
|
843
961
|
addListener(listener, rowListeners[mutator ? 1 : 0], [tableId, rowId]);
|
|
844
962
|
const addCellIdsListener = (
|
|
@@ -884,6 +1002,7 @@ const createStore = () => {
|
|
|
884
1002
|
tableIds: pair2CollSize2(tableIdsListeners),
|
|
885
1003
|
table: pairCollSize2(tableListeners),
|
|
886
1004
|
rowIds: pair2CollSize2(rowIdsListeners),
|
|
1005
|
+
sortedRowIds: pairCollSize2(sortedRowIdsListeners),
|
|
887
1006
|
row: pairCollSize2(rowListeners, collSize3),
|
|
888
1007
|
cellIds: pair2CollSize2(cellIdsListeners, collSize3),
|
|
889
1008
|
cell: pairCollSize2(cellListeners, collSize4),
|
|
@@ -895,6 +1014,7 @@ const createStore = () => {
|
|
|
895
1014
|
getTableIds,
|
|
896
1015
|
getTable,
|
|
897
1016
|
getRowIds,
|
|
1017
|
+
getSortedRowIds,
|
|
898
1018
|
getRow,
|
|
899
1019
|
getCellIds,
|
|
900
1020
|
getCell,
|
|
@@ -927,6 +1047,7 @@ const createStore = () => {
|
|
|
927
1047
|
addTableIdsListener,
|
|
928
1048
|
addTableListener,
|
|
929
1049
|
addRowIdsListener,
|
|
1050
|
+
addSortedRowIdsListener,
|
|
930
1051
|
addRowListener,
|
|
931
1052
|
addCellIdsListener,
|
|
932
1053
|
addCellListener,
|