tinybase 1.2.3 → 1.3.0-beta.0

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.
@@ -176,6 +176,32 @@ export type MapCell = (cell: CellOrUndefined) => Cell;
176
176
  */
177
177
  export type GetCell = (cellId: Id) => CellOrUndefined;
178
178
 
179
+ /**
180
+ * The TransactionListener type describes a function that is used to listen to
181
+ * the completion of a transaction for the Store.
182
+ *
183
+ * A TransactionListener is provided when using the
184
+ * addWillFinishTransactionListener and addDidFinishTransactionListener methods.
185
+ * See those methods for specific examples.
186
+ *
187
+ * When called, a TransactionListener is simply given a reference to the Store
188
+ * and a boolean to indicate whether Cell values have been touched during the
189
+ * transaction. The latter flag is intended as a hint about whether non-mutating
190
+ * listeners might be being called at the end of the transaction.
191
+ *
192
+ * Here, 'touched' means that Cell values have either been changed, or changed
193
+ * and then changed back to its original value during the transaction. The
194
+ * exception is a transaction that has been rolled back, for which the value of
195
+ * `cellsTouched` in the listener will be `false` because all changes have been
196
+ * reverted.
197
+ *
198
+ * @param store A reference to the Store that is completing a transaction.
199
+ * @param cellsTouched Whether Cell values have been touched during the
200
+ * transaction.
201
+ * @category Listener
202
+ */
203
+ export type TransactionListener = (store: Store, cellsTouched: boolean) => void;
204
+
179
205
  /**
180
206
  * The TablesListener type describes a function that is used to listen to
181
207
  * changes to the whole Store.
@@ -1652,7 +1678,7 @@ export interface Store {
1652
1678
 
1653
1679
  /**
1654
1680
  * The transaction method takes a function that makes multiple mutations to
1655
- * the store, buffering all calls to the relevant listeners until it
1681
+ * the Store, buffering all calls to the relevant listeners until it
1656
1682
  * completes.
1657
1683
  *
1658
1684
  * This method is useful for making bulk changes to the data in a Store, and
@@ -1771,6 +1797,135 @@ export interface Store {
1771
1797
  ) => boolean,
1772
1798
  ): Return;
1773
1799
 
1800
+ /**
1801
+ * The startTransaction allows you to explicitly start a transaction that will
1802
+ * make multiple mutations to the Store, buffering all calls to the relevant
1803
+ * listeners until it completes when you call the finishTransaction method.
1804
+ *
1805
+ * Transactions are useful for making bulk changes to the data in a Store, and
1806
+ * when you don't want listeners to be called as you make each change. Changes
1807
+ * are made silently during the transaction, and listeners relevant to the
1808
+ * changes you have made will instead only be called when the whole
1809
+ * transaction is complete.
1810
+ *
1811
+ * Generally it is preferable to use the transaction method to wrap a block of
1812
+ * code as a transaction. It simply calls both the startTransaction and
1813
+ * finishTransaction methods for you. See that method for several transaction
1814
+ * examples.
1815
+ *
1816
+ * Use this startTransaction method when you have a more 'open-ended'
1817
+ * transaction, such as one containing mutations triggered from other events
1818
+ * that are asynchronous or not occurring inline to your code. You must
1819
+ * remember to also call the finishTransaction method explicitly when it is
1820
+ * done, of course.
1821
+ *
1822
+ * @returns A reference to the Store.
1823
+ * @example
1824
+ * This example makes changes to two Cells, first outside, and secondly
1825
+ * within, a transaction that is explicitly started and finished. In the
1826
+ * second case, the Row listener is only called once.
1827
+ *
1828
+ * ```js
1829
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1830
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1831
+ *
1832
+ * store.setCell('pets', 'fido', 'color', 'brown');
1833
+ * store.setCell('pets', 'fido', 'sold', false);
1834
+ * // -> 'Fido changed'
1835
+ * // -> 'Fido changed'
1836
+ *
1837
+ * store.startTransaction();
1838
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1839
+ * store.setCell('pets', 'fido', 'sold', true);
1840
+ * store.finishTransaction();
1841
+ * // -> 'Fido changed'
1842
+ * ```
1843
+ * @category Transaction
1844
+ */
1845
+ startTransaction(): Store;
1846
+
1847
+ /**
1848
+ * The finishTransaction allows you to explicitly finish a transaction that
1849
+ * has made multiple mutations to the Store, triggering all calls to the
1850
+ * relevant listeners.
1851
+ *
1852
+ * Transactions are useful for making bulk changes to the data in a Store, and
1853
+ * when you don't want listeners to be called as you make each change. Changes
1854
+ * are made silently during the transaction, and listeners relevant to the
1855
+ * changes you have made will instead only be called when the whole
1856
+ * transaction is complete.
1857
+ *
1858
+ * Generally it is preferable to use the transaction method to wrap a block of
1859
+ * code as a transaction. It simply calls both the startTransaction and
1860
+ * finishTransaction methods for you. See that method for several transaction
1861
+ * examples.
1862
+ *
1863
+ * Use this finishTransaction method when you have a more 'open-ended'
1864
+ * transaction, such as one containing mutations triggered from other events
1865
+ * that are asynchronous or not occurring inline to your code. There must have
1866
+ * been a corresponding startTransaction method that this completes, of
1867
+ * course, otherwise this function has no effect.
1868
+ *
1869
+ * @param doRollback An optional callback that should return `true` if you
1870
+ * want to rollback the transaction at the end.
1871
+ * @returns A reference to the Store.
1872
+ * @example
1873
+ * This example makes changes to two Cells, first outside, and secondly
1874
+ * within, a transaction that is explicitly started and finished. In the
1875
+ * second case, the Row listener is only called once.
1876
+ *
1877
+ * ```js
1878
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1879
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1880
+ *
1881
+ * store.setCell('pets', 'fido', 'color', 'brown');
1882
+ * store.setCell('pets', 'fido', 'sold', false);
1883
+ * // -> 'Fido changed'
1884
+ * // -> 'Fido changed'
1885
+ *
1886
+ * store.startTransaction();
1887
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1888
+ * store.setCell('pets', 'fido', 'sold', true);
1889
+ * store.finishTransaction();
1890
+ * // -> 'Fido changed'
1891
+ * ```
1892
+ * @example
1893
+ * This example makes multiple changes to the Store, including some attempts
1894
+ * to update a Cell with invalid values. The `doRollback` callback receives
1895
+ * information about the changes and invalid attempts, and then judges that
1896
+ * the transaction should be rolled back to its original state.
1897
+ *
1898
+ * ```js
1899
+ * const store = createStore().setTables({
1900
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1901
+ * });
1902
+ *
1903
+ * store.startTransaction();
1904
+ * store.setCell('pets', 'fido', 'color', 'black');
1905
+ * store.setCell('pets', 'fido', 'eyes', ['left', 'right']);
1906
+ * store.setCell('pets', 'fido', 'info', {sold: null});
1907
+ * store.finishTransaction((changedCells, invalidCells) => {
1908
+ * console.log(store.getTables());
1909
+ * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
1910
+ * console.log(changedCells);
1911
+ * // -> {pets: {fido: {color: ['brown', 'black']}}}
1912
+ * console.log(invalidCells);
1913
+ * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
1914
+ * return invalidCells['pets'] != null;
1915
+ * });
1916
+ *
1917
+ * console.log(store.getTables());
1918
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1919
+ * ```
1920
+ * @category Transaction
1921
+ */
1922
+ finishTransaction(
1923
+ doRollback?: (
1924
+ changedCells: ChangedCells,
1925
+ invalidCells: InvalidCells,
1926
+ ) => boolean,
1927
+ ): Store;
1928
+
1774
1929
  /**
1775
1930
  * The forEachTable method takes a function that it will then call for each
1776
1931
  * Table in the Store.
@@ -2746,6 +2901,143 @@ export interface Store {
2746
2901
  mutator?: boolean,
2747
2902
  ): Id;
2748
2903
 
2904
+ /**
2905
+ * The addWillFinishTransactionListener method registers a listener function
2906
+ * with the Store that will be called just before other non-mutating listeners
2907
+ * are called at the end of the transaction.
2908
+ *
2909
+ * This is useful if you need to know that a set of listeners are about to be
2910
+ * called at the end of a transaction, perhaps to batch _their_ consequences
2911
+ * together.
2912
+ *
2913
+ * The provided TransactionListener will receive a reference to the Store and
2914
+ * a boolean to indicate whether Cell values have been touched during the
2915
+ * transaction. The latter flag is intended as a hint about whether
2916
+ * non-mutating listeners might be being called at the end of the transaction.
2917
+ *
2918
+ * Here, 'touched' means that Cell values have either been changed, or changed
2919
+ * and then changed back to its original value during the transaction. The
2920
+ * exception is a transaction that has been rolled back, for which the value
2921
+ * of `cellsTouched` in the listener will be `false` because all changes have
2922
+ * been reverted.
2923
+ *
2924
+ * @returns A unique Id for the listener that can later be used to remove it.
2925
+ * @example
2926
+ * This example registers a listener that is called at the end of the
2927
+ * transaction, just before its listeners will be called. The transactions
2928
+ * shown here variously change, touch, and rollback cells, demonstrating how
2929
+ * the `cellsTouched` parameter in the listener works.
2930
+ *
2931
+ * ```js
2932
+ * const store = createStore().setTables({
2933
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2934
+ * });
2935
+ * const listenerId = store.addWillFinishTransactionListener(
2936
+ * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
2937
+ * );
2938
+ * const listenerId2 = store.addTablesListener(() =>
2939
+ * console.log('Tables changed'),
2940
+ * );
2941
+ *
2942
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
2943
+ * // -> 'Cells touched: false'
2944
+ *
2945
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
2946
+ * // -> 'Cells touched: true'
2947
+ * // -> 'Tables changed'
2948
+ *
2949
+ * store.transaction(() => {
2950
+ * store.setRow('pets', 'felix', {species: 'cat'});
2951
+ * store.delRow('pets', 'felix');
2952
+ * });
2953
+ * // -> 'Cells touched: true'
2954
+ *
2955
+ * store.transaction(
2956
+ * () => store.setRow('pets', 'fido', {species: 'dog'}),
2957
+ * () => true,
2958
+ * );
2959
+ * // -> 'Cells touched: false'
2960
+ * // Transaction was rolled back.
2961
+ *
2962
+ * store.callListener(listenerId);
2963
+ * // -> 'Cells touched: undefined'
2964
+ * // It is meaningless to call this listener directly.
2965
+ *
2966
+ * store.delListener(listenerId).delListener(listenerId2);
2967
+ * ```
2968
+ * @category Listener
2969
+ */
2970
+ addWillFinishTransactionListener(listener: TransactionListener): Id;
2971
+
2972
+ /**
2973
+ * The addDidFinishTransactionListener method registers a listener function
2974
+ * with the Store that will be called just after other non-mutating listeners
2975
+ * are called at the end of the transaction.
2976
+ *
2977
+ * This is useful if you need to know that a set of listeners have just been
2978
+ * called at the end of a transaction, perhaps to batch _their_ consequences
2979
+ * together.
2980
+ *
2981
+ * The provided TransactionListener will receive a reference to the Store and
2982
+ * a boolean to indicate whether Cell values have been touched during the
2983
+ * transaction. The latter flag is intended as a hint about whether
2984
+ * non-mutating listeners might have been called at the end of the
2985
+ * transaction.
2986
+ *
2987
+ * Here, 'touched' means that Cell values have either been changed, or changed
2988
+ * and then changed back to its original value during the transaction. The
2989
+ * exception is a transaction that has been rolled back, for which the value
2990
+ * of `cellsTouched` in the listener will be `false` because all changes have
2991
+ * been reverted.
2992
+ *
2993
+ * @returns A unique Id for the listener that can later be used to remove it.
2994
+ * @example
2995
+ * This example registers a listener that is called at the end of the
2996
+ * transaction, just after its listeners have been called. The transactions
2997
+ * shown here variously change, touch, and rollback cells, demonstrating how
2998
+ * the `cellsTouched` parameter in the listener works.
2999
+ *
3000
+ * ```js
3001
+ * const store = createStore().setTables({
3002
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3003
+ * });
3004
+ * const listenerId = store.addDidFinishTransactionListener(
3005
+ * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
3006
+ * );
3007
+ * const listenerId2 = store.addTablesListener(() =>
3008
+ * console.log('Tables changed'),
3009
+ * );
3010
+ *
3011
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
3012
+ * // -> 'Cells touched: false'
3013
+ *
3014
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
3015
+ * // -> 'Tables changed'
3016
+ * // -> 'Cells touched: true'
3017
+ *
3018
+ * store.transaction(() => {
3019
+ * store.setRow('pets', 'felix', {species: 'cat'});
3020
+ * store.delRow('pets', 'felix');
3021
+ * });
3022
+ * // -> 'Cells touched: true'
3023
+ *
3024
+ * store.transaction(
3025
+ * () => store.setRow('pets', 'fido', {species: 'dog'}),
3026
+ * () => true,
3027
+ * );
3028
+ * // -> 'Cells touched: false'
3029
+ * // Transaction was rolled back.
3030
+ *
3031
+ * store.callListener(listenerId);
3032
+ * // -> 'Cells touched: undefined'
3033
+ * // It is meaningless to call this listener directly.
3034
+ *
3035
+ * store.delListener(listenerId).delListener(listenerId2);
3036
+ * ```
3037
+ * @category Listener
3038
+ */
3039
+ addDidFinishTransactionListener(listener: TransactionListener): Id;
3040
+
2749
3041
  /**
2750
3042
  * The callListener method provides a way for you to manually provoke a
2751
3043
  * listener to be called, even if the underlying data hasn't changed.
@@ -209,6 +209,7 @@ const idsChanged = (ids, id, added) =>
209
209
  mapSet(ids, id, mapGet(ids, id) == -added ? void 0 : added);
210
210
  const createStore = () => {
211
211
  let hasSchema;
212
+ let cellsTouched;
212
213
  let nextRowId = 0;
213
214
  let transactions = 0;
214
215
  const changedTableIds = mapNew();
@@ -227,6 +228,7 @@ const createStore = () => {
227
228
  const cellIdsListeners = mapNewPair();
228
229
  const cellListeners = mapNewPair();
229
230
  const invalidCellListeners = mapNewPair();
231
+ const finishTransactionListeners = mapNewPair(setNew);
230
232
  const [addListener, callListeners, delListenerImpl, callListenerImpl] =
231
233
  getListenerFunctions(() => store);
232
234
  const validateSchema = (schema) =>
@@ -459,75 +461,73 @@ const createStore = () => {
459
461
  )
460
462
  : 0;
461
463
  const callListenersForChanges = (mutator) => {
462
- if (!collIsEmpty(changedCells)) {
463
- const emptyIdListeners =
464
- collIsEmpty(cellIdsListeners[mutator]) &&
465
- collIsEmpty(rowIdsListeners[mutator]) &&
466
- collIsEmpty(tableIdsListeners[mutator]);
467
- const emptyOtherListeners =
468
- collIsEmpty(cellListeners[mutator]) &&
469
- collIsEmpty(rowListeners[mutator]) &&
470
- collIsEmpty(tableListeners[mutator]) &&
471
- collIsEmpty(tablesListeners[mutator]);
472
- if (!(emptyIdListeners && emptyOtherListeners)) {
473
- const changes = mutator
474
- ? [
475
- mapClone(changedTableIds),
476
- mapClone2(changedRowIds),
477
- mapClone(changedCellIds, mapClone2),
478
- mapClone(changedCells, mapClone2),
479
- ]
480
- : [changedTableIds, changedRowIds, changedCellIds, changedCells];
481
- if (!emptyIdListeners) {
482
- collForEach(changes[2], (rowCellIds, tableId) =>
483
- collForEach(rowCellIds, (changedIds, rowId) => {
484
- if (!collIsEmpty(changedIds)) {
485
- callListeners(cellIdsListeners[mutator], [tableId, rowId]);
486
- }
487
- }),
488
- );
489
- collForEach(changes[1], (changedIds, tableId) => {
464
+ const emptyIdListeners =
465
+ collIsEmpty(cellIdsListeners[mutator]) &&
466
+ collIsEmpty(rowIdsListeners[mutator]) &&
467
+ collIsEmpty(tableIdsListeners[mutator]);
468
+ const emptyOtherListeners =
469
+ collIsEmpty(cellListeners[mutator]) &&
470
+ collIsEmpty(rowListeners[mutator]) &&
471
+ collIsEmpty(tableListeners[mutator]) &&
472
+ collIsEmpty(tablesListeners[mutator]);
473
+ if (!(emptyIdListeners && emptyOtherListeners)) {
474
+ const changes = mutator
475
+ ? [
476
+ mapClone(changedTableIds),
477
+ mapClone2(changedRowIds),
478
+ mapClone(changedCellIds, mapClone2),
479
+ mapClone(changedCells, mapClone2),
480
+ ]
481
+ : [changedTableIds, changedRowIds, changedCellIds, changedCells];
482
+ if (!emptyIdListeners) {
483
+ collForEach(changes[2], (rowCellIds, tableId) =>
484
+ collForEach(rowCellIds, (changedIds, rowId) => {
490
485
  if (!collIsEmpty(changedIds)) {
491
- callListeners(rowIdsListeners[mutator], [tableId]);
486
+ callListeners(cellIdsListeners[mutator], [tableId, rowId]);
492
487
  }
493
- });
494
- if (!collIsEmpty(changes[0])) {
495
- callListeners(tableIdsListeners[mutator]);
488
+ }),
489
+ );
490
+ collForEach(changes[1], (changedIds, tableId) => {
491
+ if (!collIsEmpty(changedIds)) {
492
+ callListeners(rowIdsListeners[mutator], [tableId]);
496
493
  }
494
+ });
495
+ if (!collIsEmpty(changes[0])) {
496
+ callListeners(tableIdsListeners[mutator]);
497
497
  }
498
- if (!emptyOtherListeners) {
499
- let tablesChanged;
500
- collForEach(changes[3], (rows, tableId) => {
501
- let tableChanged;
502
- collForEach(rows, (cells, rowId) => {
503
- let rowChanged;
504
- collForEach(cells, ([oldCell, newCell], cellId) => {
505
- if (newCell !== oldCell) {
506
- callListeners(
507
- cellListeners[mutator],
508
- [tableId, rowId, cellId],
509
- newCell,
510
- oldCell,
511
- getCellChange,
512
- );
513
- tablesChanged = tableChanged = rowChanged = 1;
514
- }
515
- });
516
- if (rowChanged) {
498
+ }
499
+ if (!emptyOtherListeners) {
500
+ let tablesChanged;
501
+ collForEach(changes[3], (rows, tableId) => {
502
+ let tableChanged;
503
+ collForEach(rows, (cells, rowId) => {
504
+ let rowChanged;
505
+ collForEach(cells, ([oldCell, newCell], cellId) => {
506
+ if (newCell !== oldCell) {
517
507
  callListeners(
518
- rowListeners[mutator],
519
- [tableId, rowId],
508
+ cellListeners[mutator],
509
+ [tableId, rowId, cellId],
510
+ newCell,
511
+ oldCell,
520
512
  getCellChange,
521
513
  );
514
+ tablesChanged = tableChanged = rowChanged = 1;
522
515
  }
523
516
  });
524
- if (tableChanged) {
525
- callListeners(tableListeners[mutator], [tableId], getCellChange);
517
+ if (rowChanged) {
518
+ callListeners(
519
+ rowListeners[mutator],
520
+ [tableId, rowId],
521
+ getCellChange,
522
+ );
526
523
  }
527
524
  });
528
- if (tablesChanged) {
529
- callListeners(tablesListeners[mutator], [], getCellChange);
525
+ if (tableChanged) {
526
+ callListeners(tableListeners[mutator], [tableId], getCellChange);
530
527
  }
528
+ });
529
+ if (tablesChanged) {
530
+ callListeners(tablesListeners[mutator], [], getCellChange);
531
531
  }
532
532
  }
533
533
  }
@@ -656,61 +656,79 @@ const createStore = () => {
656
656
  if (transactions == -1) {
657
657
  return;
658
658
  }
659
- transactions++;
659
+ startTransaction();
660
660
  const result = actions?.();
661
- transactions--;
662
- if (transactions == 0) {
663
- transactions = 1;
664
- callInvalidCellListeners(1);
665
- callListenersForChanges(1);
666
- transactions = -1;
667
- if (
668
- doRollback?.(
669
- mapToObj(
670
- changedCells,
671
- (table) =>
672
- mapToObj(
673
- table,
674
- (row) =>
675
- mapToObj(
676
- row,
677
- (cells) => [...cells],
678
- ([oldCell, newCell]) => oldCell === newCell,
679
- ),
680
- objIsEmpty,
681
- ),
682
- objIsEmpty,
683
- ),
684
- mapToObj(invalidCells, (map) => mapToObj(map, mapToObj)),
685
- )
686
- ) {
661
+ finishTransaction(doRollback);
662
+ return result;
663
+ };
664
+ const startTransaction = () => {
665
+ transactions++;
666
+ return store;
667
+ };
668
+ const finishTransaction = (doRollback) => {
669
+ if (transactions > 0) {
670
+ transactions--;
671
+ if (transactions == 0) {
672
+ cellsTouched = !collIsEmpty(changedCells);
687
673
  transactions = 1;
688
- collForEach(changedCells, (table, tableId) =>
689
- collForEach(table, (row, rowId) =>
690
- collForEach(row, ([oldCell], cellId) =>
691
- isUndefined(oldCell)
692
- ? delCell(tableId, rowId, cellId, true)
693
- : setCell(tableId, rowId, cellId, oldCell),
674
+ callInvalidCellListeners(1);
675
+ if (cellsTouched) {
676
+ callListenersForChanges(1);
677
+ }
678
+ transactions = -1;
679
+ if (
680
+ doRollback?.(
681
+ mapToObj(
682
+ changedCells,
683
+ (table) =>
684
+ mapToObj(
685
+ table,
686
+ (row) =>
687
+ mapToObj(
688
+ row,
689
+ (cells) => [...cells],
690
+ ([oldCell, newCell]) => oldCell === newCell,
691
+ ),
692
+ objIsEmpty,
693
+ ),
694
+ objIsEmpty,
694
695
  ),
695
- ),
696
+ mapToObj(invalidCells, (map) => mapToObj(map, mapToObj)),
697
+ )
698
+ ) {
699
+ transactions = 1;
700
+ collForEach(changedCells, (table, tableId) =>
701
+ collForEach(table, (row, rowId) =>
702
+ collForEach(row, ([oldCell], cellId) =>
703
+ isUndefined(oldCell)
704
+ ? delCell(tableId, rowId, cellId, true)
705
+ : setCell(tableId, rowId, cellId, oldCell),
706
+ ),
707
+ ),
708
+ );
709
+ transactions = -1;
710
+ cellsTouched = false;
711
+ }
712
+ callListeners(finishTransactionListeners[0], [], cellsTouched);
713
+ callInvalidCellListeners(0);
714
+ if (cellsTouched) {
715
+ callListenersForChanges(0);
716
+ }
717
+ callListeners(finishTransactionListeners[1], [], cellsTouched);
718
+ transactions = 0;
719
+ arrayForEach(
720
+ [
721
+ changedCells,
722
+ invalidCells,
723
+ changedTableIds,
724
+ changedRowIds,
725
+ changedCellIds,
726
+ ],
727
+ collClear,
696
728
  );
697
- transactions = -1;
698
729
  }
699
- callInvalidCellListeners(0);
700
- callListenersForChanges(0);
701
- transactions = 0;
702
- arrayForEach(
703
- [
704
- changedCells,
705
- invalidCells,
706
- changedTableIds,
707
- changedRowIds,
708
- changedCellIds,
709
- ],
710
- collClear,
711
- );
712
730
  }
713
- return result;
731
+ return store;
714
732
  };
715
733
  const forEachTable = (tableCallback) =>
716
734
  collForEach(tablesMap, (tableMap, tableId) =>
@@ -752,6 +770,10 @@ const createStore = () => {
752
770
  rowId,
753
771
  cellId,
754
772
  ]);
773
+ const addWillFinishTransactionListener = (listener) =>
774
+ addListener(listener, finishTransactionListeners[0]);
775
+ const addDidFinishTransactionListener = (listener) =>
776
+ addListener(listener, finishTransactionListeners[1]);
755
777
  const callListener = (listenerId) => {
756
778
  callListenerImpl(listenerId, [getTableIds, getRowIds, getCellIds], (ids) =>
757
779
  isUndefined(ids[2]) ? [] : arrayPair(getCell(...ids)),
@@ -800,6 +822,8 @@ const createStore = () => {
800
822
  delCell,
801
823
  delSchema,
802
824
  transaction,
825
+ startTransaction,
826
+ finishTransaction,
803
827
  forEachTable,
804
828
  forEachRow,
805
829
  forEachCell,
@@ -811,6 +835,8 @@ const createStore = () => {
811
835
  addCellIdsListener,
812
836
  addCellListener,
813
837
  addInvalidCellListener,
838
+ addWillFinishTransactionListener,
839
+ addDidFinishTransactionListener,
814
840
  callListener,
815
841
  delListener,
816
842
  getListenerStats,