tinybase 3.0.0-beta.0 → 3.0.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.
- package/bin/cli.js +1 -1
- package/lib/checkpoints.d.ts +18 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +18 -3
- package/lib/debug/checkpoints.js +97 -49
- package/lib/debug/indexes.js +31 -16
- package/lib/debug/metrics.js +31 -16
- package/lib/debug/persisters.d.ts +33 -23
- package/lib/debug/persisters.js +10 -5
- package/lib/debug/queries.js +2 -2
- package/lib/debug/relationships.js +31 -16
- package/lib/debug/store.d.ts +2053 -381
- package/lib/debug/store.js +444 -106
- package/lib/debug/tinybase.js +512 -138
- package/lib/debug/tools.d.ts +109 -38
- package/lib/debug/tools.js +759 -453
- package/lib/debug/ui-react.d.ts +1218 -138
- package/lib/debug/ui-react.js +163 -12
- package/lib/es6/checkpoints.d.ts +18 -3
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters.d.ts +33 -23
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.d.ts +2053 -381
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.d.ts +109 -38
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.d.ts +1218 -138
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- 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/persisters.d.ts +33 -23
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +2053 -381
- 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/tools.d.ts +109 -38
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/ui-react.d.ts +1218 -138
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.d.ts +18 -3
- 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/persisters.d.ts +33 -23
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.d.ts +2053 -381
- 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/tools.d.ts +109 -38
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.d.ts +1218 -138
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/checkpoints.d.ts +18 -3
- package/lib/umd-es6/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters.d.ts +33 -23
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.d.ts +2053 -381
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +109 -38
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.d.ts +1218 -138
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +20 -20
- package/readme.md +27 -16
package/lib/debug/store.d.ts
CHANGED
|
@@ -90,16 +90,64 @@ export type Cell = string | number | boolean;
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* The CellOrUndefined type is a data structure representing the data in a
|
|
93
|
-
* single cell or the value `undefined`.
|
|
93
|
+
* single cell, or the value `undefined`.
|
|
94
94
|
*
|
|
95
|
-
* This is used when describing a Cell that is present _or_ that is not present
|
|
96
|
-
*
|
|
95
|
+
* This is used when describing a Cell that is present _or_ that is not present,
|
|
96
|
+
* such as when it has been deleted, or when describing a previous state where
|
|
97
97
|
* the Cell value has since been added.
|
|
98
98
|
*
|
|
99
99
|
* @category Store
|
|
100
100
|
*/
|
|
101
101
|
export type CellOrUndefined = Cell | undefined;
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* The Values type is the data structure representing all the keyed values in a
|
|
105
|
+
* Store.
|
|
106
|
+
*
|
|
107
|
+
* A Values object is used when setting values with the setValues method, and
|
|
108
|
+
* when getting them back out again with the getValues method. A Values object
|
|
109
|
+
* is a regular JavaScript object containing individual Value objects, keyed by
|
|
110
|
+
* their Id.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```js
|
|
114
|
+
* const values: Values = {open: true, employees: 4};
|
|
115
|
+
* ```
|
|
116
|
+
* @category Store
|
|
117
|
+
* @since v3.0.0
|
|
118
|
+
*/
|
|
119
|
+
export type Values = {[valueId: Id]: Value};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The Value type is the data structure representing the data in a single keyed
|
|
123
|
+
* value.
|
|
124
|
+
*
|
|
125
|
+
* A Value is used when setting a value with the setValue method, and when
|
|
126
|
+
* getting it back out again with the getValue method. A Value is a JavaScript
|
|
127
|
+
* string, number, or boolean.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```js
|
|
131
|
+
* const value: Value = 'dog';
|
|
132
|
+
* ```
|
|
133
|
+
* @category Store
|
|
134
|
+
* @since v3.0.0
|
|
135
|
+
*/
|
|
136
|
+
export type Value = string | number | boolean;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The ValueOrUndefined type is a data structure representing the data in a
|
|
140
|
+
* single value, or the value `undefined`.
|
|
141
|
+
*
|
|
142
|
+
* This is used when describing a Value that is present _or_ that is not
|
|
143
|
+
* present, such as when it has been deleted, or when describing a previous
|
|
144
|
+
* state where the Value has since been added.
|
|
145
|
+
*
|
|
146
|
+
* @category Store
|
|
147
|
+
* @since v3.0.0
|
|
148
|
+
*/
|
|
149
|
+
export type ValueOrUndefined = Value | undefined;
|
|
150
|
+
|
|
103
151
|
/**
|
|
104
152
|
* The TableCallback type describes a function that takes a Table's Id and a
|
|
105
153
|
* callback to loop over each Row within it.
|
|
@@ -150,6 +198,21 @@ export type RowCallback = (
|
|
|
150
198
|
*/
|
|
151
199
|
export type CellCallback = (cellId: Id, cell: Cell) => void;
|
|
152
200
|
|
|
201
|
+
/**
|
|
202
|
+
* The ValueCallback type describes a function that takes a Value's Id and its
|
|
203
|
+
* actual value.
|
|
204
|
+
*
|
|
205
|
+
* A ValueCallback is provided when using the forEachValue method, so that you
|
|
206
|
+
* can do something based on every Value in a Store. See that method for
|
|
207
|
+
* specific examples.
|
|
208
|
+
*
|
|
209
|
+
* @param valueId The Id of the Value that the callback can operate on.
|
|
210
|
+
* @param value The Value itself.
|
|
211
|
+
* @category Callback
|
|
212
|
+
* @since v3.0.0
|
|
213
|
+
*/
|
|
214
|
+
export type ValueCallback = (valueId: Id, value: Value) => void;
|
|
215
|
+
|
|
153
216
|
/**
|
|
154
217
|
* The MapCell type describes a function that takes an existing Cell value and
|
|
155
218
|
* returns another.
|
|
@@ -163,6 +226,20 @@ export type CellCallback = (cellId: Id, cell: Cell) => void;
|
|
|
163
226
|
*/
|
|
164
227
|
export type MapCell = (cell: CellOrUndefined) => Cell;
|
|
165
228
|
|
|
229
|
+
/**
|
|
230
|
+
* The MapValue type describes a function that takes an existing Value and
|
|
231
|
+
* returns another.
|
|
232
|
+
*
|
|
233
|
+
* A MapValue can be provided in the setValue method to map an existing Value to
|
|
234
|
+
* a new one, such as when incrementing a number. See that method for specific
|
|
235
|
+
* examples.
|
|
236
|
+
*
|
|
237
|
+
* @param value The current Value to map to a new Value.
|
|
238
|
+
* @category Callback
|
|
239
|
+
* @since v3.0.0
|
|
240
|
+
*/
|
|
241
|
+
export type MapValue = (value: ValueOrUndefined) => Value;
|
|
242
|
+
|
|
166
243
|
/**
|
|
167
244
|
* The GetCell type describes a function that takes a Id and returns the Cell
|
|
168
245
|
* value for a particular Row.
|
|
@@ -176,6 +253,32 @@ export type MapCell = (cell: CellOrUndefined) => Cell;
|
|
|
176
253
|
*/
|
|
177
254
|
export type GetCell = (cellId: Id) => CellOrUndefined;
|
|
178
255
|
|
|
256
|
+
/**
|
|
257
|
+
* The DoRollback type describes a function that you can use to rollback the
|
|
258
|
+
* transaction if it did not complete to your satisfaction.
|
|
259
|
+
*
|
|
260
|
+
* A DoRollback can be provided when calling the transaction method or the
|
|
261
|
+
* finishTransaction method. See those methods for specific examples.
|
|
262
|
+
*
|
|
263
|
+
* It is called with `changedCells`, `invalidCells`, `changedValues`, and
|
|
264
|
+
* `invalidValues` parameters, which inform you of the net changes that have
|
|
265
|
+
* been made during the transaction, and any invalid attempts to do so,
|
|
266
|
+
* respectively.
|
|
267
|
+
*
|
|
268
|
+
* @param changedCells Any Cells that were changed during the transaction.
|
|
269
|
+
* @param invalidCells Any invalid attempts to change Cells.
|
|
270
|
+
* @param changedValues Any Values that were changed during the transaction,
|
|
271
|
+
* since v3.0.0.
|
|
272
|
+
* @param invalidValues Any invalid attempts to change Values, since v3.0.0.
|
|
273
|
+
* @category Callback
|
|
274
|
+
*/
|
|
275
|
+
export type DoRollback = (
|
|
276
|
+
changedCells: ChangedCells,
|
|
277
|
+
invalidCells: InvalidCells,
|
|
278
|
+
changedValues: ChangedValues,
|
|
279
|
+
invalidValues: InvalidValues,
|
|
280
|
+
) => boolean;
|
|
281
|
+
|
|
179
282
|
/**
|
|
180
283
|
* The TransactionListener type describes a function that is used to listen to
|
|
181
284
|
* the completion of a transaction for the Store.
|
|
@@ -185,22 +288,28 @@ export type GetCell = (cellId: Id) => CellOrUndefined;
|
|
|
185
288
|
* See those methods for specific examples.
|
|
186
289
|
*
|
|
187
290
|
* When called, a TransactionListener is simply given a reference to the Store
|
|
188
|
-
* and
|
|
189
|
-
* transaction. The
|
|
190
|
-
* listeners might be being called at the end of the transaction.
|
|
291
|
+
* and booleans to indicate whether Cell or Value data has been touched during
|
|
292
|
+
* the transaction. The two flags are intended as a hint about whether
|
|
293
|
+
* non-mutating listeners might be being called at the end of the transaction.
|
|
191
294
|
*
|
|
192
|
-
* Here, 'touched' means that Cell
|
|
193
|
-
* and then changed back to its original value during the transaction.
|
|
194
|
-
* exception is a transaction that has been rolled back, for which the value
|
|
195
|
-
* `cellsTouched` in the listener will be `false` because
|
|
196
|
-
* reverted.
|
|
295
|
+
* Here, 'touched' means that Cell or Value data has either been changed, or
|
|
296
|
+
* changed and then changed back to its original value during the transaction.
|
|
297
|
+
* The exception is a transaction that has been rolled back, for which the value
|
|
298
|
+
* of `cellsTouched` and `valuesTouched` in the listener will be `false` because
|
|
299
|
+
* all changes have been reverted.
|
|
197
300
|
*
|
|
198
301
|
* @param store A reference to the Store that is completing a transaction.
|
|
199
302
|
* @param cellsTouched Whether Cell values have been touched during the
|
|
200
303
|
* transaction.
|
|
304
|
+
* @param valuesTouched Whether Values have been touched during the
|
|
305
|
+
* transaction, since v3.0.0.
|
|
201
306
|
* @category Listener
|
|
202
307
|
*/
|
|
203
|
-
export type TransactionListener = (
|
|
308
|
+
export type TransactionListener = (
|
|
309
|
+
store: Store,
|
|
310
|
+
cellsTouched: boolean,
|
|
311
|
+
valuesTouched: boolean,
|
|
312
|
+
) => void;
|
|
204
313
|
|
|
205
314
|
/**
|
|
206
315
|
* The TablesListener type describes a function that is used to listen to
|
|
@@ -403,6 +512,79 @@ export type CellListener = (
|
|
|
403
512
|
getCellChange: GetCellChange | undefined,
|
|
404
513
|
) => void;
|
|
405
514
|
|
|
515
|
+
/**
|
|
516
|
+
* The ValuesListener type describes a function that is used to listen to
|
|
517
|
+
* changes to all the Values in a Store.
|
|
518
|
+
*
|
|
519
|
+
* A ValuesListener is provided when using the addValuesListener method. See
|
|
520
|
+
* that method for specific examples.
|
|
521
|
+
*
|
|
522
|
+
* When called, a ValuesListener is given a reference to the Store and a
|
|
523
|
+
* GetValueChange function that can be used to query Values before and after the
|
|
524
|
+
* current transaction.
|
|
525
|
+
*
|
|
526
|
+
* Note that if the listener was manually forced to be called (with the
|
|
527
|
+
* callListener method rather than due to a real change in the Store), the
|
|
528
|
+
* GetValueChange function will not be present.
|
|
529
|
+
*
|
|
530
|
+
* @param store A reference to the Store that changed.
|
|
531
|
+
* @param getValueChange A function that returns information about any Value's
|
|
532
|
+
* changes.
|
|
533
|
+
* @category Listener
|
|
534
|
+
*/
|
|
535
|
+
export type ValuesListener = (
|
|
536
|
+
store: Store,
|
|
537
|
+
getValueChange: GetValueChange | undefined,
|
|
538
|
+
) => void;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* The ValueIdsListener type describes a function that is used to listen to
|
|
542
|
+
* changes to the Value Ids in a Store.
|
|
543
|
+
*
|
|
544
|
+
* A ValueIdsListener is provided when using the addValueIdsListener method. See
|
|
545
|
+
* that method for specific examples.
|
|
546
|
+
*
|
|
547
|
+
* When called, a ValueIdsListener is given a reference to the Store.
|
|
548
|
+
*
|
|
549
|
+
* @param store A reference to the Store that changed.
|
|
550
|
+
* @category Listener
|
|
551
|
+
*/
|
|
552
|
+
export type ValueIdsListener = (store: Store) => void;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The ValueListener type describes a function that is used to listen to changes
|
|
556
|
+
* to a Value.
|
|
557
|
+
*
|
|
558
|
+
* A ValueListener is provided when using the addValueListener method. See that
|
|
559
|
+
* method for specific examples.
|
|
560
|
+
*
|
|
561
|
+
* When called, a ValueListener is given a reference to the Store and the Id of
|
|
562
|
+
* Value that changed. It is also given the new value of the Value, the old
|
|
563
|
+
* value of the Value, and a GetValueChange function that can be used to query
|
|
564
|
+
* Values before and after the current transaction.
|
|
565
|
+
*
|
|
566
|
+
* Note that if the listener was manually forced to be called (with the
|
|
567
|
+
* callListener method rather than due to a real change in the Store), the
|
|
568
|
+
* GetValueChange function will not be present and the new and old values of the
|
|
569
|
+
* Value will be the same.
|
|
570
|
+
*
|
|
571
|
+
* @param store A reference to the Store that changed.
|
|
572
|
+
* @param valueId The Id of the Value that changed.
|
|
573
|
+
* @param newValue The new value of the Value that changed.
|
|
574
|
+
* @param oldValue The old value of the Value that changed.
|
|
575
|
+
* @param getValueChange A function that returns information about any Value's
|
|
576
|
+
* changes.
|
|
577
|
+
* @category Listener
|
|
578
|
+
* @since v3.0.0
|
|
579
|
+
*/
|
|
580
|
+
export type ValueListener = (
|
|
581
|
+
store: Store,
|
|
582
|
+
valueId: Id,
|
|
583
|
+
newValue: Value,
|
|
584
|
+
oldValue: Value,
|
|
585
|
+
getValueChange: GetValueChange | undefined,
|
|
586
|
+
) => void;
|
|
587
|
+
|
|
406
588
|
/**
|
|
407
589
|
* The InvalidCellListener type describes a function that is used to listen to
|
|
408
590
|
* attempts to set invalid data to a Cell.
|
|
@@ -411,7 +593,7 @@ export type CellListener = (
|
|
|
411
593
|
* method. See that method for specific examples.
|
|
412
594
|
*
|
|
413
595
|
* When called, a InvalidCellListener is given a reference to the Store, the Id
|
|
414
|
-
* of the Table, the Id of the Row, and the Id of Cell that
|
|
596
|
+
* of the Table, the Id of the Row, and the Id of Cell that was being attempted
|
|
415
597
|
* to be changed. It is also given the invalid value of the Cell, which could
|
|
416
598
|
* have been of absolutely any type. Since there could have been multiple failed
|
|
417
599
|
* attempts to set the Cell within a single transaction, this is an array
|
|
@@ -433,6 +615,32 @@ export type InvalidCellListener = (
|
|
|
433
615
|
invalidCells: any[],
|
|
434
616
|
) => void;
|
|
435
617
|
|
|
618
|
+
/**
|
|
619
|
+
* The InvalidValueListener type describes a function that is used to listen to
|
|
620
|
+
* attempts to set invalid data to a Value.
|
|
621
|
+
*
|
|
622
|
+
* A InvalidValueListener is provided when using the addInvalidValueListener
|
|
623
|
+
* method. See that method for specific examples.
|
|
624
|
+
*
|
|
625
|
+
* When called, a InvalidValueListener is given a reference to the Store and the
|
|
626
|
+
* Id of Value that was being attempted to be changed. It is also given the
|
|
627
|
+
* invalid value of the Value, which could have been of absolutely any type.
|
|
628
|
+
* Since there could have been multiple failed attempts to set the Value within
|
|
629
|
+
* a single transaction, this is an array containing each attempt,
|
|
630
|
+
* chronologically.
|
|
631
|
+
*
|
|
632
|
+
* @param store A reference to the Store that was being changed.
|
|
633
|
+
* @param valueId The Id of the Value that was being changed.
|
|
634
|
+
* @param invalidValues An array of the Values that were invalid.
|
|
635
|
+
* @category Listener
|
|
636
|
+
* @since v3.0.0
|
|
637
|
+
*/
|
|
638
|
+
export type InvalidValueListener = (
|
|
639
|
+
store: Store,
|
|
640
|
+
valueId: Id,
|
|
641
|
+
invalidValues: any[],
|
|
642
|
+
) => void;
|
|
643
|
+
|
|
436
644
|
/**
|
|
437
645
|
* The GetCellChange type describes a function that returns information about
|
|
438
646
|
* any Cell's changes during a transaction.
|
|
@@ -467,20 +675,52 @@ export type CellChange = [
|
|
|
467
675
|
];
|
|
468
676
|
|
|
469
677
|
/**
|
|
470
|
-
* The
|
|
471
|
-
*
|
|
678
|
+
* The GetValueChange type describes a function that returns information about
|
|
679
|
+
* any Value's changes during a transaction.
|
|
680
|
+
*
|
|
681
|
+
* A GetValueChange function is provided to every listener when called due the
|
|
682
|
+
* Store changing. The listener can then fetch the previous value of a Value
|
|
683
|
+
* before the current transaction, the new value after it, and a convenience
|
|
684
|
+
* flag that indicates that the value has changed.
|
|
685
|
+
*
|
|
686
|
+
* @param valueId The Id of the Value to inspect.
|
|
687
|
+
* @returns A ValueChange array containing information about the Value's
|
|
688
|
+
* changes.
|
|
689
|
+
* @category Listener
|
|
690
|
+
*/
|
|
691
|
+
export type GetValueChange = (valueId: Id) => ValueChange;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The ValueChange type describes a Value's changes during a transaction.
|
|
695
|
+
*
|
|
696
|
+
* This is returned by the GetValueChange function that is provided to every
|
|
697
|
+
* listener when called. This array contains the previous value of a Value
|
|
698
|
+
* before the current transaction, the new value after it, and a convenience
|
|
699
|
+
* flag that indicates that the value has changed.
|
|
700
|
+
*
|
|
701
|
+
* @category Listener
|
|
702
|
+
*/
|
|
703
|
+
export type ValueChange = [
|
|
704
|
+
changed: boolean,
|
|
705
|
+
oldValue: ValueOrUndefined,
|
|
706
|
+
newValue: ValueOrUndefined,
|
|
707
|
+
];
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* The TablesSchema type describes the tabular structure of a Store in terms of
|
|
711
|
+
* valid Table Ids and the types of Cell that can exist within them.
|
|
472
712
|
*
|
|
473
|
-
* A
|
|
713
|
+
* A TablesSchema comprises a JavaScript object describing each Table, in turn a
|
|
474
714
|
* nested JavaScript object containing information about each Cell and its
|
|
475
|
-
* CellSchema. It is provided to the
|
|
715
|
+
* CellSchema. It is provided to the setTablesSchema method.
|
|
476
716
|
*
|
|
477
717
|
* @example
|
|
478
|
-
* When applied to a Store, this
|
|
479
|
-
* which each Row may contain a string `species` Cell, and is
|
|
480
|
-
* contain a boolean `sold` Cell that defaults to `false`.
|
|
718
|
+
* When applied to a Store, this TablesSchema only allows one Table called
|
|
719
|
+
* `pets`, in which each Row may contain a string `species` Cell, and is
|
|
720
|
+
* guaranteed to contain a boolean `sold` Cell that defaults to `false`.
|
|
481
721
|
*
|
|
482
722
|
*```js
|
|
483
|
-
* const
|
|
723
|
+
* const tableSchema: TablesSchema = {
|
|
484
724
|
* pets: {
|
|
485
725
|
* species: {type: 'string'},
|
|
486
726
|
* sold: {type: 'boolean', default: false},
|
|
@@ -489,7 +729,7 @@ export type CellChange = [
|
|
|
489
729
|
* ```
|
|
490
730
|
* @category Schema
|
|
491
731
|
*/
|
|
492
|
-
export type
|
|
732
|
+
export type TablesSchema = {
|
|
493
733
|
[tableId: Id]: {
|
|
494
734
|
[cellId: Id]: CellSchema;
|
|
495
735
|
};
|
|
@@ -520,18 +760,62 @@ export type Schema = {
|
|
|
520
760
|
* @category Schema
|
|
521
761
|
*/
|
|
522
762
|
export type CellSchema =
|
|
523
|
-
| {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
763
|
+
| {type: 'string'; default?: string}
|
|
764
|
+
| {type: 'number'; default?: number}
|
|
765
|
+
| {type: 'boolean'; default?: boolean};
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* The ValuesSchema type describes the keyed Values that can be set in a Store
|
|
769
|
+
* and their types.
|
|
770
|
+
*
|
|
771
|
+
* A ValuesSchema comprises a JavaScript object describing each Value and its
|
|
772
|
+
* ValueSchema. It is provided to the setValuesSchema method.
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* When applied to a Store, this ValuesSchema only allows one boolean Value
|
|
776
|
+
* called `open`, that defaults to `false`.
|
|
777
|
+
*
|
|
778
|
+
*```js
|
|
779
|
+
* const valuesSchema: ValuesSchema = {
|
|
780
|
+
* open: {type: 'boolean', default: false},
|
|
781
|
+
* };
|
|
782
|
+
* ```
|
|
783
|
+
* @category Schema
|
|
784
|
+
* @since v3.0.0
|
|
785
|
+
*/
|
|
786
|
+
export type ValuesSchema = {
|
|
787
|
+
[valueId: Id]: ValueSchema;
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* The ValueSchema type describes what values are allowed for keyed Values in a
|
|
792
|
+
* Store.
|
|
793
|
+
*
|
|
794
|
+
* A ValueSchema specifies the type of the Value (`string`, `boolean`, or
|
|
795
|
+
* `number`), and what the default value can be when an explicit value is not
|
|
796
|
+
* specified.
|
|
797
|
+
*
|
|
798
|
+
* If a default value is provided (and its type is correct), you can be certain
|
|
799
|
+
* that the Value will always be present in a Store.
|
|
800
|
+
*
|
|
801
|
+
* If the default value is _not_ provided (or its type is incorrect), the Value
|
|
802
|
+
* may not be present in the Store, but when present you can be guaranteed it is
|
|
803
|
+
* of the correct type.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* When applied to a Store, this ValueSchema ensures a boolean Value is always
|
|
807
|
+
* present, and defaults it to `false`.
|
|
808
|
+
*
|
|
809
|
+
*```js
|
|
810
|
+
* const requiredBoolean: ValueSchema = {type: 'boolean', default: false};
|
|
811
|
+
* ```
|
|
812
|
+
* @category Schema
|
|
813
|
+
* @since v3.0.0
|
|
814
|
+
*/
|
|
815
|
+
export type ValueSchema =
|
|
816
|
+
| {type: 'string'; default?: string}
|
|
817
|
+
| {type: 'number'; default?: number}
|
|
818
|
+
| {type: 'boolean'; default?: boolean};
|
|
535
819
|
|
|
536
820
|
/**
|
|
537
821
|
* The ChangedCells type describes the Cell values that have been changed during
|
|
@@ -539,7 +823,8 @@ export type CellSchema =
|
|
|
539
823
|
* transaction should be rolled back.
|
|
540
824
|
*
|
|
541
825
|
* A ChangedCells object is provided to the `doRollback` callback when using the
|
|
542
|
-
* transaction method. See
|
|
826
|
+
* transaction method and the finishTransaction method. See those methods for
|
|
827
|
+
* specific examples.
|
|
543
828
|
*
|
|
544
829
|
* This type is a nested structure of Table, Row, and Cell objects, much like
|
|
545
830
|
* the Tables object, but one which provides both the old and new Cell values in
|
|
@@ -564,13 +849,15 @@ export type ChangedCells = {
|
|
|
564
849
|
};
|
|
565
850
|
};
|
|
566
851
|
};
|
|
852
|
+
|
|
567
853
|
/**
|
|
568
854
|
* The InvalidCells type describes the invalid Cell values that have been
|
|
569
855
|
* attempted during a transaction, primarily used so that you can indicate
|
|
570
856
|
* whether the transaction should be rolled back.
|
|
571
857
|
*
|
|
572
858
|
* An InvalidCells object is provided to the `doRollback` callback when using
|
|
573
|
-
* the transaction method
|
|
859
|
+
* the transaction method and the finishTransaction method. See those methods
|
|
860
|
+
* for specific examples.
|
|
574
861
|
*
|
|
575
862
|
* This type is a nested structure of Table, Row, and Cell objects, much like
|
|
576
863
|
* the Tables object, but one for which Cell values are listed in array (much
|
|
@@ -588,6 +875,53 @@ export type InvalidCells = {
|
|
|
588
875
|
};
|
|
589
876
|
};
|
|
590
877
|
|
|
878
|
+
/**
|
|
879
|
+
* The ChangedValues type describes the Values that have been changed during a
|
|
880
|
+
* transaction, primarily used so that you can indicate whether the transaction
|
|
881
|
+
* should be rolled back.
|
|
882
|
+
*
|
|
883
|
+
* A ChangedValues object is provided to the `doRollback` callback when using
|
|
884
|
+
* the transaction method and the finishTransaction method. See those methods
|
|
885
|
+
* for specific examples.
|
|
886
|
+
*
|
|
887
|
+
* This type is an object containing the old and new Values in two-part arrays.
|
|
888
|
+
* These are describing the state of each changed Value in Store at the _start_
|
|
889
|
+
* of the transaction, and by the _end_ of the transaction.
|
|
890
|
+
*
|
|
891
|
+
* Hence, an `undefined` value for the first item in the array means that the
|
|
892
|
+
* Value was added during the transaction. An `undefined` value for the second
|
|
893
|
+
* item in the array means that the Value was removed during the transaction. An
|
|
894
|
+
* array with two different Values indicates that it was changed. The two-part
|
|
895
|
+
* array will never contain two items of the same value (including two
|
|
896
|
+
* `undefined` values), even if, during the transaction, a Value was changed to
|
|
897
|
+
* a different value and then changed back.
|
|
898
|
+
*
|
|
899
|
+
* @category Transaction
|
|
900
|
+
* @since v3.0.0
|
|
901
|
+
*/
|
|
902
|
+
export type ChangedValues = {
|
|
903
|
+
[valueId: Id]: [ValueOrUndefined, ValueOrUndefined];
|
|
904
|
+
};
|
|
905
|
+
/**
|
|
906
|
+
* The InvalidValues type describes the invalid Values that have been attempted
|
|
907
|
+
* during a transaction, primarily used so that you can indicate whether the
|
|
908
|
+
* transaction should be rolled back.
|
|
909
|
+
*
|
|
910
|
+
* An InvalidValues object is provided to the `doRollback` callback when using
|
|
911
|
+
* the transaction method and the finishTransaction method. See those methods
|
|
912
|
+
* for specific examples.
|
|
913
|
+
*
|
|
914
|
+
* This type is an object containing each invalid Value's attempt listed in
|
|
915
|
+
* array (much like the InvalidValueListener type) so that multiple failed
|
|
916
|
+
* attempts to change a Value during the transaction are described.
|
|
917
|
+
*
|
|
918
|
+
* @category Transaction
|
|
919
|
+
* @since v3.0.0
|
|
920
|
+
*/
|
|
921
|
+
export type InvalidValues = {
|
|
922
|
+
[valueId: Id]: any[];
|
|
923
|
+
};
|
|
924
|
+
|
|
591
925
|
/**
|
|
592
926
|
* The StoreListenerStats type describes the number of listeners registered with
|
|
593
927
|
* the Store, and can be used for debugging purposes.
|
|
@@ -636,6 +970,26 @@ export type StoreListenerStats = {
|
|
|
636
970
|
* The number of InvalidCellListener functions registered with the Store.
|
|
637
971
|
*/
|
|
638
972
|
invalidCell?: number;
|
|
973
|
+
/**
|
|
974
|
+
* The number of ValuesListener functions registered with the Store, since
|
|
975
|
+
* v3.0.0.
|
|
976
|
+
*/
|
|
977
|
+
values?: number;
|
|
978
|
+
/**
|
|
979
|
+
* The number of ValueIdsListener functions registered with the Store, since
|
|
980
|
+
* v3.0.0.
|
|
981
|
+
*/
|
|
982
|
+
valueIds?: number;
|
|
983
|
+
/**
|
|
984
|
+
* The number of ValueListener functions registered with the Store, since
|
|
985
|
+
* v3.0.0.
|
|
986
|
+
*/
|
|
987
|
+
value?: number;
|
|
988
|
+
/**
|
|
989
|
+
* The number of InvalidValueListener functions registered with the Store,
|
|
990
|
+
* since v3.0.0.
|
|
991
|
+
*/
|
|
992
|
+
invalidValue?: number;
|
|
639
993
|
/**
|
|
640
994
|
* The number of TransactionListener functions registered with the Store.
|
|
641
995
|
*/
|
|
@@ -643,13 +997,39 @@ export type StoreListenerStats = {
|
|
|
643
997
|
};
|
|
644
998
|
|
|
645
999
|
/**
|
|
646
|
-
* A Store is the main location for keeping
|
|
1000
|
+
* A Store is the main location for keeping both tabular data and keyed values.
|
|
647
1001
|
*
|
|
648
1002
|
* Create a Store easily with the createStore function. From there, you can set
|
|
649
|
-
* and get data, add listeners for when the data changes, set
|
|
1003
|
+
* and get data, add listeners for when the data changes, set schemas, and so
|
|
650
1004
|
* on.
|
|
651
1005
|
*
|
|
652
|
-
* A Store has
|
|
1006
|
+
* A Store has two facets. It can contain keyed Values, and independently, it
|
|
1007
|
+
* can contain tabular Tables data. These two facets have similar APIs but can
|
|
1008
|
+
* be used entirely independently: you can use only tables, only keyed Values,
|
|
1009
|
+
* or both tables _and_ keyed Values - all in a single Store.
|
|
1010
|
+
*
|
|
1011
|
+
* # Keyed values
|
|
1012
|
+
*
|
|
1013
|
+
* The keyed value support is best thought of as a flat JavaScript object. The
|
|
1014
|
+
* Store contains a number of Value objects, each with a unique ID, and which is
|
|
1015
|
+
* a string, boolean, or number:
|
|
1016
|
+
*
|
|
1017
|
+
* ```json
|
|
1018
|
+
* { // Store
|
|
1019
|
+
* "value1": "one", // Value (string)
|
|
1020
|
+
* "value2": true, // Value (boolean)
|
|
1021
|
+
* "value3": 3, // Value (number)
|
|
1022
|
+
* ...
|
|
1023
|
+
* }
|
|
1024
|
+
* ```
|
|
1025
|
+
*
|
|
1026
|
+
* In its default form, a Store has no sense of a structured schema for the
|
|
1027
|
+
* Values. However, you _can_ optionally specify a ValuesSchema for a Store,
|
|
1028
|
+
* which then usefully constrains and defaults the Values you can use.
|
|
1029
|
+
*
|
|
1030
|
+
* # Tabular data
|
|
1031
|
+
*
|
|
1032
|
+
* The tabular data exists in a simple hierarchical structure:
|
|
653
1033
|
*
|
|
654
1034
|
* - The Store contains a number of Table objects.
|
|
655
1035
|
* - Each Table contains a number of Row objects.
|
|
@@ -676,11 +1056,11 @@ export type StoreListenerStats = {
|
|
|
676
1056
|
* }
|
|
677
1057
|
* ```
|
|
678
1058
|
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* which then usefully constrains the Table and Cell Ids (and
|
|
683
|
-
* can use.
|
|
1059
|
+
* Again, by default Store has no sense of a structured schema. As long as they
|
|
1060
|
+
* are unique within their own parent, the Id keys can each be any string you
|
|
1061
|
+
* want. However, as you _can_ optionally specify a TablesSchema for the tabular
|
|
1062
|
+
* data in a Store, which then usefully constrains the Table and Cell Ids (and
|
|
1063
|
+
* Cell values) you can use.
|
|
684
1064
|
*
|
|
685
1065
|
* # Setting and getting data
|
|
686
1066
|
*
|
|
@@ -700,6 +1080,9 @@ export type StoreListenerStats = {
|
|
|
700
1080
|
*
|
|
701
1081
|
* |Type|Get data|Set data|Delete data|Add a listener|
|
|
702
1082
|
* |-|-|-|-|-|
|
|
1083
|
+
* |Values|getValues|setValues|delValues|addValuesListener|
|
|
1084
|
+
* |Value Ids|getValueIds|-|-|addValueIdsListener|
|
|
1085
|
+
* |Value|getValue|setValue|delValue|addValueListener|
|
|
703
1086
|
* |Tables|getTables|setTables|delTables|addTablesListener|
|
|
704
1087
|
* |Table Ids|getTableIds|-|-|addTableIdsListener|
|
|
705
1088
|
* |Table|getTable|setTable|delTable|addTableListener|
|
|
@@ -709,13 +1092,14 @@ export type StoreListenerStats = {
|
|
|
709
1092
|
* |Cell Ids|getCellIds|-|-|addCellIdsListener|
|
|
710
1093
|
* |Cell|getCell|setCell|delCell|addCellListener|
|
|
711
1094
|
*
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
1095
|
+
* There are two extra methods to manipulate Row objects. The addRow method is
|
|
1096
|
+
* like the setRow method but automatically assigns it a new unique Id. And the
|
|
1097
|
+
* setPartialRow method lets you update multiple Cell values in a Row without
|
|
1098
|
+
* affecting the others. (There is a similar setPartialValues method to do the
|
|
1099
|
+
* same for the Values in a Store.)
|
|
716
1100
|
*
|
|
717
|
-
* You can listen to attempts to write invalid data to a Cell with the
|
|
718
|
-
* addInvalidCellListener method.
|
|
1101
|
+
* You can listen to attempts to write invalid data to a Value or Cell with the
|
|
1102
|
+
* addInvalidValueListener method or addInvalidCellListener method.
|
|
719
1103
|
*
|
|
720
1104
|
* The transaction method is used to wrap multiple changes to the Store so that
|
|
721
1105
|
* the relevant listeners only fire once.
|
|
@@ -733,17 +1117,17 @@ export type StoreListenerStats = {
|
|
|
733
1117
|
* Read more about setting and changing data in The Basics guides, and about
|
|
734
1118
|
* listeners in the Listening to Stores guide.
|
|
735
1119
|
*
|
|
736
|
-
* # Creating a
|
|
1120
|
+
* # Creating a schema
|
|
737
1121
|
*
|
|
738
|
-
* You can set a
|
|
739
|
-
*
|
|
1122
|
+
* You can set a ValuesSchema and a TablesSchema with the setValuesSchema method
|
|
1123
|
+
* and setTablesSchema method respectively. A TablesSchema constrains the Table
|
|
740
1124
|
* Ids the Store can have, and the types of Cell data in each Table. Each Cell
|
|
741
1125
|
* requires its type to be specified, and can also take a default value for when
|
|
742
1126
|
* it's not specified.
|
|
743
1127
|
*
|
|
744
|
-
* You can also get a serialization of the
|
|
745
|
-
* getSchemaJson method, and remove the
|
|
746
|
-
* method.
|
|
1128
|
+
* You can also get a serialization of the schemas out of the Store with
|
|
1129
|
+
* the getSchemaJson method, and remove the schemas altogether with
|
|
1130
|
+
* the delValuesSchema method and delTablesSchema method.
|
|
747
1131
|
*
|
|
748
1132
|
* Read more about schemas in the Using Schemas guide.
|
|
749
1133
|
*
|
|
@@ -755,6 +1139,7 @@ export type StoreListenerStats = {
|
|
|
755
1139
|
*
|
|
756
1140
|
* ||Checking existence|Iterator|
|
|
757
1141
|
* |-|-|-|
|
|
1142
|
+
* |Value|hasValue|forEachValue|
|
|
758
1143
|
* |Table|hasTable|forEachTable|
|
|
759
1144
|
* |Row|hasRow|forEachRow|
|
|
760
1145
|
* |Cell|hasCell|forEachCell|
|
|
@@ -1136,6 +1521,92 @@ export interface Store {
|
|
|
1136
1521
|
*/
|
|
1137
1522
|
getCell(tableId: Id, rowId: Id, cellId: Id): CellOrUndefined;
|
|
1138
1523
|
|
|
1524
|
+
/**
|
|
1525
|
+
* The getValues method returns an object containing the entire set of keyed
|
|
1526
|
+
* Values in the Store.
|
|
1527
|
+
*
|
|
1528
|
+
* Note that this returns a copy of, rather than a reference to the underlying
|
|
1529
|
+
* data, so changes made to the returned object are not made to the Store
|
|
1530
|
+
* itself.
|
|
1531
|
+
*
|
|
1532
|
+
* @returns An object containing the entire data of the Values.
|
|
1533
|
+
* @example
|
|
1534
|
+
* This example retrieves the keyed Values data in a Store.
|
|
1535
|
+
*
|
|
1536
|
+
* ```js
|
|
1537
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
1538
|
+
* console.log(store.getValues());
|
|
1539
|
+
* // -> {open: true, employees: 3}
|
|
1540
|
+
* ```
|
|
1541
|
+
* @example
|
|
1542
|
+
* This example retrieves a Values from a Store that has none, returning an
|
|
1543
|
+
* empty object.
|
|
1544
|
+
*
|
|
1545
|
+
* ```js
|
|
1546
|
+
* const store = createStore();
|
|
1547
|
+
* console.log(store.getValues());
|
|
1548
|
+
* // -> {}
|
|
1549
|
+
* ```
|
|
1550
|
+
* @category Getter
|
|
1551
|
+
* @since v3.0.0
|
|
1552
|
+
*/
|
|
1553
|
+
getValues(): Values;
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* The getValueIds method returns the Ids of every Value in a Store.
|
|
1557
|
+
*
|
|
1558
|
+
* Note that this returns a copy of, rather than a reference, to the list of
|
|
1559
|
+
* Ids, so changes made to the list are not made to the Store itself.
|
|
1560
|
+
*
|
|
1561
|
+
* @returns An array of the Ids of every Value in the Store.
|
|
1562
|
+
* @example
|
|
1563
|
+
* This example retrieves the Value Ids in a Store.
|
|
1564
|
+
*
|
|
1565
|
+
* ```js
|
|
1566
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
1567
|
+
* console.log(store.getValueIds());
|
|
1568
|
+
* // -> ['open', 'employees']
|
|
1569
|
+
* ```
|
|
1570
|
+
* @example
|
|
1571
|
+
* This example retrieves the Value Ids of a Store that has had none set,
|
|
1572
|
+
* returning an empty array.
|
|
1573
|
+
*
|
|
1574
|
+
* ```js
|
|
1575
|
+
* const store = createStore();
|
|
1576
|
+
* console.log(store.getValueIds());
|
|
1577
|
+
* // -> []
|
|
1578
|
+
* ```
|
|
1579
|
+
* @category Getter
|
|
1580
|
+
* @since v3.0.0
|
|
1581
|
+
*/
|
|
1582
|
+
getValueIds(): Ids;
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* The getValue method returns a single keyed Value in the Store.
|
|
1586
|
+
*
|
|
1587
|
+
* @param valueId The Id of the Value in the Store.
|
|
1588
|
+
* @returns The Value, or `undefined`.
|
|
1589
|
+
* @example
|
|
1590
|
+
* This example retrieves a single Value.
|
|
1591
|
+
*
|
|
1592
|
+
* ```js
|
|
1593
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
1594
|
+
* console.log(store.getValue('employees'));
|
|
1595
|
+
* // -> 3
|
|
1596
|
+
* ```
|
|
1597
|
+
* @example
|
|
1598
|
+
* This example retrieves a Value that does not exist, returning `undefined`.
|
|
1599
|
+
*
|
|
1600
|
+
* ```js
|
|
1601
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
1602
|
+
* console.log(store.getValue('website'));
|
|
1603
|
+
* // -> undefined
|
|
1604
|
+
* ```
|
|
1605
|
+
* @category Getter
|
|
1606
|
+
* @since v3.0.0
|
|
1607
|
+
*/
|
|
1608
|
+
getValue(valueId: Id): ValueOrUndefined;
|
|
1609
|
+
|
|
1139
1610
|
/**
|
|
1140
1611
|
* The hasTables method returns a boolean indicating whether any Table objects
|
|
1141
1612
|
* exist in the Store.
|
|
@@ -1220,61 +1691,235 @@ export interface Store {
|
|
|
1220
1691
|
hasCell(tableId: Id, rowId: Id, cellId: Id): boolean;
|
|
1221
1692
|
|
|
1222
1693
|
/**
|
|
1223
|
-
* The
|
|
1224
|
-
* the Store.
|
|
1225
|
-
*
|
|
1226
|
-
* @returns A string serialization of all of the Tables in the Store.
|
|
1227
|
-
* @example
|
|
1228
|
-
* This example serializes the contents of a Store.
|
|
1694
|
+
* The hasTables method returns a boolean indicating whether any Values exist
|
|
1695
|
+
* in the Store.
|
|
1229
1696
|
*
|
|
1230
|
-
*
|
|
1231
|
-
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
1232
|
-
* console.log(store.getJson());
|
|
1233
|
-
* // -> '{"pets":{"fido":{"species":"dog"}}}'
|
|
1234
|
-
* ```
|
|
1697
|
+
* @returns Whether any Values exist.
|
|
1235
1698
|
* @example
|
|
1236
|
-
* This example
|
|
1699
|
+
* This example shows simple existence checks.
|
|
1237
1700
|
*
|
|
1238
1701
|
* ```js
|
|
1239
1702
|
* const store = createStore();
|
|
1240
|
-
* console.log(store.
|
|
1241
|
-
* // ->
|
|
1703
|
+
* console.log(store.hasValues());
|
|
1704
|
+
* // -> false
|
|
1705
|
+
* store.setValues({open: true});
|
|
1706
|
+
* console.log(store.hasValues());
|
|
1707
|
+
* // -> true
|
|
1708
|
+
* ```
|
|
1709
|
+
* @category Getter
|
|
1710
|
+
* @since v3.0.0
|
|
1711
|
+
*/
|
|
1712
|
+
hasValues(): boolean;
|
|
1713
|
+
|
|
1714
|
+
/**
|
|
1715
|
+
* The hasValue method returns a boolean indicating whether a given Value
|
|
1716
|
+
* exists in the Store.
|
|
1717
|
+
*
|
|
1718
|
+
* @param valueId The Id of a possible Value in the Store.
|
|
1719
|
+
* @returns Whether a Value with that Id exists in the Store.
|
|
1720
|
+
* @example
|
|
1721
|
+
* This example shows two simple Value existence checks.
|
|
1722
|
+
*
|
|
1723
|
+
* ```js
|
|
1724
|
+
* const store = createStore().setValues({open: true});
|
|
1725
|
+
* console.log(store.hasValue('open'));
|
|
1726
|
+
* // -> true
|
|
1727
|
+
* console.log(store.hasValue('employees'));
|
|
1728
|
+
* // -> false
|
|
1729
|
+
* ```
|
|
1730
|
+
* @category Getter
|
|
1731
|
+
* @since v3.0.0
|
|
1732
|
+
*/
|
|
1733
|
+
hasValue(valueId: Id): boolean;
|
|
1734
|
+
|
|
1735
|
+
/**
|
|
1736
|
+
* The getTablesJson method returns a string serialization of all of the
|
|
1737
|
+
* Tables in the Store.
|
|
1738
|
+
*
|
|
1739
|
+
* @returns A string serialization of all of the Tables in the Store.
|
|
1740
|
+
* @example
|
|
1741
|
+
* This example serializes the contents of a Store.
|
|
1742
|
+
*
|
|
1743
|
+
* ```js
|
|
1744
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
1745
|
+
* console.log(store.getTablesJson());
|
|
1746
|
+
* // -> '{"pets":{"fido":{"species":"dog"}}}'
|
|
1747
|
+
* ```
|
|
1748
|
+
* @example
|
|
1749
|
+
* This example serializes the contents of an empty Store.
|
|
1750
|
+
*
|
|
1751
|
+
* ```js
|
|
1752
|
+
* const store = createStore();
|
|
1753
|
+
* console.log(store.getTablesJson());
|
|
1754
|
+
* // -> '{}'
|
|
1755
|
+
* ```
|
|
1756
|
+
* @category Getter
|
|
1757
|
+
* @since v3.0.0
|
|
1758
|
+
*/
|
|
1759
|
+
getTablesJson(): Json;
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* The getValuesJson method returns a string serialization of all of the
|
|
1763
|
+
* keyed Values in the Store.
|
|
1764
|
+
*
|
|
1765
|
+
* @returns A string serialization of all of the Values in the Store.
|
|
1766
|
+
* @example
|
|
1767
|
+
* This example serializes the keyed value contents of a Store.
|
|
1768
|
+
*
|
|
1769
|
+
* ```js
|
|
1770
|
+
* const store = createStore().setValues({open: true});
|
|
1771
|
+
* console.log(store.getValuesJson());
|
|
1772
|
+
* // -> '{"open":true}'
|
|
1773
|
+
* ```
|
|
1774
|
+
* @example
|
|
1775
|
+
* This example serializes the contents of an empty Store.
|
|
1776
|
+
*
|
|
1777
|
+
* ```js
|
|
1778
|
+
* const store = createStore();
|
|
1779
|
+
* console.log(store.getValuesJson());
|
|
1780
|
+
* // -> '{}'
|
|
1781
|
+
* ```
|
|
1782
|
+
* @category Getter
|
|
1783
|
+
* @since v3.0.0
|
|
1784
|
+
*/
|
|
1785
|
+
getValuesJson(): Json;
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* The getJson method returns a string serialization of all the Store content:
|
|
1789
|
+
* both the Tables and the keyed Values.
|
|
1790
|
+
*
|
|
1791
|
+
* From v3.0.0 onwards, the serialization is of an array with two entries. The
|
|
1792
|
+
* first is the Tables object, the second the Values. In previous versions
|
|
1793
|
+
* (before the existence of the Values data structure), it was a sole object
|
|
1794
|
+
* of Tables.
|
|
1795
|
+
*
|
|
1796
|
+
* @returns A string serialization of the Tables and Values in the Store.
|
|
1797
|
+
* @example
|
|
1798
|
+
* This example serializes the tabular and keyed value contents of a Store.
|
|
1799
|
+
*
|
|
1800
|
+
* ```js
|
|
1801
|
+
* const store = createStore()
|
|
1802
|
+
* .setTables({pets: {fido: {species: 'dog'}}})
|
|
1803
|
+
* .setValues({open: true});
|
|
1804
|
+
* console.log(store.getJson());
|
|
1805
|
+
* // -> '[{"pets":{"fido":{"species":"dog"}}},{"open":true}]'
|
|
1806
|
+
* ```
|
|
1807
|
+
* @example
|
|
1808
|
+
* This example serializes the contents of an empty Store.
|
|
1809
|
+
*
|
|
1810
|
+
* ```js
|
|
1811
|
+
* const store = createStore();
|
|
1812
|
+
* console.log(store.getJson());
|
|
1813
|
+
* // -> '[{},{}]'
|
|
1242
1814
|
* ```
|
|
1243
1815
|
* @category Getter
|
|
1244
1816
|
*/
|
|
1245
1817
|
getJson(): Json;
|
|
1246
1818
|
|
|
1247
1819
|
/**
|
|
1248
|
-
* The
|
|
1249
|
-
* the Store.
|
|
1820
|
+
* The getTablesSchemaJson method returns a string serialization of the
|
|
1821
|
+
* TablesSchema of the Store.
|
|
1250
1822
|
*
|
|
1251
|
-
* If no
|
|
1252
|
-
*
|
|
1253
|
-
* object, `{}`.
|
|
1823
|
+
* If no TablesSchema has been set on the Store (or if it has been removed
|
|
1824
|
+
* with the delTablesSchema method), then it will return the serialization of
|
|
1825
|
+
* an empty object, `{}`.
|
|
1254
1826
|
*
|
|
1255
|
-
* @returns A string serialization of the
|
|
1827
|
+
* @returns A string serialization of the TablesSchema of the Store.
|
|
1256
1828
|
* @example
|
|
1257
|
-
* This example serializes the
|
|
1829
|
+
* This example serializes the TablesSchema of a Store.
|
|
1258
1830
|
*
|
|
1259
1831
|
* ```js
|
|
1260
|
-
* const store = createStore().
|
|
1832
|
+
* const store = createStore().setTablesSchema({
|
|
1261
1833
|
* pets: {
|
|
1262
1834
|
* species: {type: 'string'},
|
|
1263
1835
|
* sold: {type: 'boolean'},
|
|
1264
1836
|
* },
|
|
1265
1837
|
* });
|
|
1266
|
-
* console.log(store.
|
|
1838
|
+
* console.log(store.getTablesSchemaJson());
|
|
1267
1839
|
* // -> '{"pets":{"species":{"type":"string"},"sold":{"type":"boolean"}}}'
|
|
1268
1840
|
* ```
|
|
1269
1841
|
* @example
|
|
1270
|
-
* This example serializes the
|
|
1842
|
+
* This example serializes the TablesSchema of an empty Store.
|
|
1271
1843
|
*
|
|
1272
1844
|
* ```js
|
|
1273
1845
|
* const store = createStore();
|
|
1274
|
-
* console.log(store.
|
|
1846
|
+
* console.log(store.getTablesSchemaJson());
|
|
1275
1847
|
* // -> '{}'
|
|
1276
1848
|
* ```
|
|
1277
1849
|
* @category Getter
|
|
1850
|
+
* @since v3.0.0
|
|
1851
|
+
*/
|
|
1852
|
+
getTablesSchemaJson(): Json;
|
|
1853
|
+
|
|
1854
|
+
/**
|
|
1855
|
+
* The getValuesSchemaJson method returns a string serialization of the
|
|
1856
|
+
* ValuesSchema of the Store.
|
|
1857
|
+
*
|
|
1858
|
+
* If no ValuesSchema has been set on the Store (or if it has been removed
|
|
1859
|
+
* with the delValuesSchema method), then it will return the serialization of
|
|
1860
|
+
* an empty object, `{}`.
|
|
1861
|
+
*
|
|
1862
|
+
* @returns A string serialization of the ValuesSchema of the Store.
|
|
1863
|
+
* @example
|
|
1864
|
+
* This example serializes the ValuesSchema of a Store.
|
|
1865
|
+
*
|
|
1866
|
+
* ```js
|
|
1867
|
+
* const store = createStore().setValuesSchema({
|
|
1868
|
+
* open: {type: 'boolean', default: false},
|
|
1869
|
+
* });
|
|
1870
|
+
* console.log(store.getValuesSchemaJson());
|
|
1871
|
+
* // -> '{"open":{"type":"boolean","default":false}}'
|
|
1872
|
+
* ```
|
|
1873
|
+
* @example
|
|
1874
|
+
* This example serializes the ValuesSchema of an empty Store.
|
|
1875
|
+
*
|
|
1876
|
+
* ```js
|
|
1877
|
+
* const store = createStore();
|
|
1878
|
+
* console.log(store.getValuesSchemaJson());
|
|
1879
|
+
* // -> '{}'
|
|
1880
|
+
* ```
|
|
1881
|
+
* @category Getter
|
|
1882
|
+
* @since v3.0.0
|
|
1883
|
+
*/
|
|
1884
|
+
getValuesSchemaJson(): Json;
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* The getSchemaJson method returns a string serialization of both the
|
|
1888
|
+
* TablesSchema and ValuesSchema of the Store.
|
|
1889
|
+
*
|
|
1890
|
+
* From v3.0.0 onwards, the serialization is of an array with two entries. The
|
|
1891
|
+
* first is the TablesSchema object, the second the ValuesSchema. In previous
|
|
1892
|
+
* versions (before the existence of the ValuesSchema data structure), it was
|
|
1893
|
+
* a sole object of TablesSchema.
|
|
1894
|
+
*
|
|
1895
|
+
* @returns A string serialization of the TablesSchema and ValuesSchema of the
|
|
1896
|
+
* Store.
|
|
1897
|
+
* @example
|
|
1898
|
+
* This example serializes the TablesSchema and ValuesSchema of a Store.
|
|
1899
|
+
*
|
|
1900
|
+
* ```js
|
|
1901
|
+
* const store = createStore()
|
|
1902
|
+
* .setTablesSchema({
|
|
1903
|
+
* pets: {
|
|
1904
|
+
* price: {type: 'number'},
|
|
1905
|
+
* },
|
|
1906
|
+
* })
|
|
1907
|
+
* .setValuesSchema({
|
|
1908
|
+
* open: {type: 'boolean'},
|
|
1909
|
+
* });
|
|
1910
|
+
* console.log(store.getSchemaJson());
|
|
1911
|
+
* // -> '[{"pets":{"price":{"type":"number"}}},{"open":{"type":"boolean"}}]'
|
|
1912
|
+
* ```
|
|
1913
|
+
* @example
|
|
1914
|
+
* This example serializes the TablesSchema and ValuesSchema of an empty
|
|
1915
|
+
* Store.
|
|
1916
|
+
*
|
|
1917
|
+
* ```js
|
|
1918
|
+
* const store = createStore();
|
|
1919
|
+
* console.log(store.getSchemaJson());
|
|
1920
|
+
* // -> '[{},{}]'
|
|
1921
|
+
* ```
|
|
1922
|
+
* @category Getter
|
|
1278
1923
|
*/
|
|
1279
1924
|
getSchemaJson(): Json;
|
|
1280
1925
|
|
|
@@ -1285,14 +1930,14 @@ export interface Store {
|
|
|
1285
1930
|
* Id changes resulting from it.
|
|
1286
1931
|
*
|
|
1287
1932
|
* Any part of the provided object that is invalid (either according to the
|
|
1288
|
-
* Tables type, or because it does not match a
|
|
1289
|
-
* Store), will be ignored silently.
|
|
1933
|
+
* Tables type, or because it does not match a TablesSchema associated with
|
|
1934
|
+
* the Store), will be ignored silently.
|
|
1290
1935
|
*
|
|
1291
1936
|
* Assuming that at least some of the provided Tables object is valid, any
|
|
1292
1937
|
* data that was already present in the Store will be completely overwritten.
|
|
1293
1938
|
* If the object is completely invalid, no change will be made to the Store.
|
|
1294
1939
|
*
|
|
1295
|
-
* The method returns a reference to the Store
|
|
1940
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
1296
1941
|
* can be chained in a fluent style.
|
|
1297
1942
|
*
|
|
1298
1943
|
* @param tables The data of the Store to be set.
|
|
@@ -1334,7 +1979,7 @@ export interface Store {
|
|
|
1334
1979
|
* Id changes resulting from it.
|
|
1335
1980
|
*
|
|
1336
1981
|
* Any part of the provided object that is invalid (either according to the
|
|
1337
|
-
* Table type, or because it does not match a
|
|
1982
|
+
* Table type, or because it does not match a TablesSchema associated with the
|
|
1338
1983
|
* Store), will be ignored silently.
|
|
1339
1984
|
*
|
|
1340
1985
|
* Assuming that at least some of the provided Table object is valid, any data
|
|
@@ -1342,7 +1987,7 @@ export interface Store {
|
|
|
1342
1987
|
* overwritten. If the object is completely invalid, no change will be made to
|
|
1343
1988
|
* the Store.
|
|
1344
1989
|
*
|
|
1345
|
-
* The method returns a reference to the Store
|
|
1990
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
1346
1991
|
* can be chained in a fluent style.
|
|
1347
1992
|
*
|
|
1348
1993
|
* @param tableId The Id of the Table in the Store.
|
|
@@ -1385,15 +2030,15 @@ export interface Store {
|
|
|
1385
2030
|
* Id changes resulting from it.
|
|
1386
2031
|
*
|
|
1387
2032
|
* Any part of the provided object that is invalid (either according to the
|
|
1388
|
-
* Row type, or because it does not match a
|
|
1389
|
-
* will be ignored silently.
|
|
2033
|
+
* Row type, or because it does not match a TablesSchema associated with the
|
|
2034
|
+
* Store), will be ignored silently.
|
|
1390
2035
|
*
|
|
1391
2036
|
* Assuming that at least some of the provided Row object is valid, any data
|
|
1392
2037
|
* that was already present in the Store for that Row will be completely
|
|
1393
2038
|
* overwritten. If the object is completely invalid, no change will be made to
|
|
1394
2039
|
* the Store.
|
|
1395
2040
|
*
|
|
1396
|
-
* The method returns a reference to the Store
|
|
2041
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
1397
2042
|
* can be chained in a fluent style.
|
|
1398
2043
|
*
|
|
1399
2044
|
* @param tableId The Id of the Table in the Store.
|
|
@@ -1435,8 +2080,8 @@ export interface Store {
|
|
|
1435
2080
|
* Id changes resulting from it.
|
|
1436
2081
|
*
|
|
1437
2082
|
* Any part of the provided object that is invalid (either according to the
|
|
1438
|
-
* Row type, or because it does not match a
|
|
1439
|
-
* will be ignored silently.
|
|
2083
|
+
* Row type, or because it does not match a TablesSchema associated with the
|
|
2084
|
+
* Store), will be ignored silently.
|
|
1440
2085
|
*
|
|
1441
2086
|
* Assuming that at least some of the provided Row object is valid, a new Row
|
|
1442
2087
|
* will be created. If the object is completely invalid, no change will be
|
|
@@ -1489,13 +2134,13 @@ export interface Store {
|
|
|
1489
2134
|
*
|
|
1490
2135
|
* Any part of the provided object that is invalid (either according to the
|
|
1491
2136
|
* Row type, or because, when combined with the current Row data, it does not
|
|
1492
|
-
* match a
|
|
2137
|
+
* match a TablesSchema associated with the Store), will be ignored silently.
|
|
1493
2138
|
*
|
|
1494
2139
|
* Assuming that at least some of the provided Row object is valid, it will be
|
|
1495
2140
|
* merged with the data that was already present in the Store. If the object
|
|
1496
2141
|
* is completely invalid, no change will be made to the Store.
|
|
1497
2142
|
*
|
|
1498
|
-
* The method returns a reference to the Store
|
|
2143
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
1499
2144
|
* can be chained in a fluent style.
|
|
1500
2145
|
*
|
|
1501
2146
|
* @param tableId The Id of the Table in the Store.
|
|
@@ -1539,7 +2184,7 @@ export interface Store {
|
|
|
1539
2184
|
* Id changes resulting from it.
|
|
1540
2185
|
*
|
|
1541
2186
|
* If the Cell value is invalid (either because of its type, or because it
|
|
1542
|
-
* does not match a
|
|
2187
|
+
* does not match a TablesSchema associated with the Store), will be ignored
|
|
1543
2188
|
* silently.
|
|
1544
2189
|
*
|
|
1545
2190
|
* As well as string, number, or boolean Cell types, this method can also take
|
|
@@ -1547,7 +2192,7 @@ export interface Store {
|
|
|
1547
2192
|
* maps it. This is useful if you want to efficiently increment a value
|
|
1548
2193
|
* without fetching it first, for example.
|
|
1549
2194
|
*
|
|
1550
|
-
* The method returns a reference to the Store
|
|
2195
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
1551
2196
|
* can be chained in a fluent style.
|
|
1552
2197
|
*
|
|
1553
2198
|
* @param tableId The Id of the Table in the Store.
|
|
@@ -1591,53 +2236,391 @@ export interface Store {
|
|
|
1591
2236
|
setCell(tableId: Id, rowId: Id, cellId: Id, cell: Cell | MapCell): Store;
|
|
1592
2237
|
|
|
1593
2238
|
/**
|
|
1594
|
-
* The
|
|
1595
|
-
*
|
|
2239
|
+
* The setValues method takes an object and sets all the Values in the Store.
|
|
2240
|
+
*
|
|
2241
|
+
* This method will cause listeners to be called for any Value or Id changes
|
|
2242
|
+
* resulting from it.
|
|
2243
|
+
*
|
|
2244
|
+
* Any part of the provided object that is invalid (either according to the
|
|
2245
|
+
* Values type, or because it does not match a ValuesSchema associated with
|
|
2246
|
+
* the Store), will be ignored silently.
|
|
2247
|
+
*
|
|
2248
|
+
* Assuming that at least some of the provided Values object is valid, any
|
|
2249
|
+
* data that was already present in the Store for that Values will be
|
|
2250
|
+
* completely overwritten. If the object is completely invalid, no change will
|
|
2251
|
+
* be made to the Store.
|
|
2252
|
+
*
|
|
2253
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
2254
|
+
* can be chained in a fluent style.
|
|
2255
|
+
*
|
|
2256
|
+
* @param values The Values object to be set.
|
|
2257
|
+
* @returns A reference to the Store.
|
|
2258
|
+
* @example
|
|
2259
|
+
* This example sets the Values of a Store.
|
|
2260
|
+
*
|
|
2261
|
+
* ```js
|
|
2262
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
2263
|
+
* console.log(store.getValues());
|
|
2264
|
+
* // -> {open: true, employees: 3}
|
|
2265
|
+
* ```
|
|
2266
|
+
* @example
|
|
2267
|
+
* This example attempts to set the data of an existing Store with partly
|
|
2268
|
+
* invalid, and then completely invalid, Values objects.
|
|
2269
|
+
*
|
|
2270
|
+
* ```js
|
|
2271
|
+
* const store = createStore().setValues({open: true});
|
|
2272
|
+
*
|
|
2273
|
+
* store.setValues({employees: 3, bug: []});
|
|
2274
|
+
* console.log(store.getValues());
|
|
2275
|
+
* // -> {employees: 3}
|
|
2276
|
+
*
|
|
2277
|
+
* store.setValues(42);
|
|
2278
|
+
* console.log(store.getValues());
|
|
2279
|
+
* // -> {employees: 3}
|
|
2280
|
+
* ```
|
|
2281
|
+
* @category Setter
|
|
2282
|
+
* @since v3.0.0
|
|
2283
|
+
*/
|
|
2284
|
+
setValues(values: Values): Store;
|
|
2285
|
+
|
|
2286
|
+
/**
|
|
2287
|
+
* The setPartialValues method takes an object and sets its Values in the
|
|
2288
|
+
* Store, but leaving existing Values unaffected.
|
|
2289
|
+
*
|
|
2290
|
+
* This method will cause listeners to be called for any Values or Id changes
|
|
2291
|
+
* resulting from it.
|
|
2292
|
+
*
|
|
2293
|
+
* Any part of the provided object that is invalid (either according to the
|
|
2294
|
+
* Values type, or because, when combined with the current Values data, it
|
|
2295
|
+
* does not match a ValuesSchema associated with the Store), will be ignored
|
|
2296
|
+
* silently.
|
|
2297
|
+
*
|
|
2298
|
+
* Assuming that at least some of the provided Values object is valid, it will
|
|
2299
|
+
* be merged with the data that was already present in the Store. If the
|
|
2300
|
+
* object is completely invalid, no change will be made to the Store.
|
|
2301
|
+
*
|
|
2302
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
2303
|
+
* can be chained in a fluent style.
|
|
2304
|
+
*
|
|
2305
|
+
* @param partialValues The Values to be set.
|
|
2306
|
+
* @returns A reference to the Store.
|
|
2307
|
+
* @example
|
|
2308
|
+
* This example sets some of the keyed value data in a Store.
|
|
2309
|
+
*
|
|
2310
|
+
* ```js
|
|
2311
|
+
* const store = createStore().setValues({open: true});
|
|
2312
|
+
* store.setPartialValues({employees: 3});
|
|
2313
|
+
* console.log(store.getValues());
|
|
2314
|
+
* // -> {open: true, employees: 3}
|
|
2315
|
+
* ```
|
|
2316
|
+
* @example
|
|
2317
|
+
* This example attempts to set some of the data of an existing Store with
|
|
2318
|
+
* partly invalid, and then completely invalid, Values objects.
|
|
2319
|
+
*
|
|
2320
|
+
* ```js
|
|
2321
|
+
* const store = createStore().setValues({open: true});
|
|
2322
|
+
*
|
|
2323
|
+
* store.setPartialValues({employees: 3, bug: []});
|
|
2324
|
+
* console.log(store.getValues());
|
|
2325
|
+
* // -> {open: true, employees: 3}
|
|
2326
|
+
*
|
|
2327
|
+
* store.setPartialValues(42);
|
|
2328
|
+
* console.log(store.getValues());
|
|
2329
|
+
* // -> {open: true, employees: 3}
|
|
2330
|
+
* ```
|
|
2331
|
+
* @category Setter
|
|
2332
|
+
* @since v3.0.0
|
|
2333
|
+
*/
|
|
2334
|
+
setPartialValues(partialValues: Values): Store;
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* The setValue method sets a single keyed Value in the Store.
|
|
2338
|
+
*
|
|
2339
|
+
* This method will cause listeners to be called for any Value, or Id changes
|
|
2340
|
+
* resulting from it.
|
|
2341
|
+
*
|
|
2342
|
+
* If the Value is invalid (either because of its type, or because it does not
|
|
2343
|
+
* match a ValuesSchema associated with the Store), will be ignored silently.
|
|
2344
|
+
*
|
|
2345
|
+
* As well as string, number, or boolean Value types, this method can also
|
|
2346
|
+
* take a MapValue function that takes the current Value as a parameter and
|
|
2347
|
+
* maps it. This is useful if you want to efficiently increment a value
|
|
2348
|
+
* without fetching it first, for example.
|
|
2349
|
+
*
|
|
2350
|
+
* The method returns a reference to the Store so that subsequent operations
|
|
2351
|
+
* can be chained in a fluent style.
|
|
2352
|
+
*
|
|
2353
|
+
* @param valueId The Id of the Value in the Store.
|
|
2354
|
+
* @param value The Value to be set, or a MapValue function to update it.
|
|
2355
|
+
* @returns A reference to the Store.
|
|
2356
|
+
* @example
|
|
2357
|
+
* This example sets a single Value.
|
|
2358
|
+
*
|
|
2359
|
+
* ```js
|
|
2360
|
+
* const store = createStore().setValue('open', true);
|
|
2361
|
+
* console.log(store.getValues());
|
|
2362
|
+
* // -> {open: true}
|
|
2363
|
+
* ```
|
|
2364
|
+
* @example
|
|
2365
|
+
* This example sets the data of a single Value by mapping the existing Value.
|
|
2366
|
+
*
|
|
2367
|
+
* ```js
|
|
2368
|
+
* const increment = (value) => value + 1;
|
|
2369
|
+
* const store = createStore().setValues({employees: 3});
|
|
2370
|
+
*
|
|
2371
|
+
* store.setValue('employees', increment);
|
|
2372
|
+
* console.log(store.getValue('employees'));
|
|
2373
|
+
* // -> 4
|
|
2374
|
+
* ```
|
|
2375
|
+
* @example
|
|
2376
|
+
* This example attempts to set an invalid Value.
|
|
2377
|
+
*
|
|
2378
|
+
* ```js
|
|
2379
|
+
* const store = createStore().setValues({employees: 3});
|
|
2380
|
+
*
|
|
2381
|
+
* store.setValue('bug', []);
|
|
2382
|
+
* console.log(store.getValues());
|
|
2383
|
+
* // -> {employees: 3}
|
|
2384
|
+
* ```
|
|
2385
|
+
* @category Setter
|
|
2386
|
+
* @since v3.0.0
|
|
2387
|
+
*/
|
|
2388
|
+
setValue(valueId: Id, value: Value | MapValue): Store;
|
|
2389
|
+
|
|
2390
|
+
/**
|
|
2391
|
+
* The setTablesJson method takes a string serialization of all of the Tables
|
|
2392
|
+
* in the Store and attempts to update them to that.
|
|
1596
2393
|
*
|
|
1597
2394
|
* If the JSON cannot be parsed, this will fail silently. If it can be parsed,
|
|
1598
2395
|
* it will then be subject to the same validation rules as the setTables
|
|
1599
|
-
* method (according to the Tables type, and matching any
|
|
1600
|
-
* with the Store).
|
|
2396
|
+
* method (according to the Tables type, and matching any TablesSchema
|
|
2397
|
+
* associated with the Store).
|
|
1601
2398
|
*
|
|
1602
|
-
* @param
|
|
2399
|
+
* @param tablesJson A string serialization of all of the Tables in the Store.
|
|
1603
2400
|
* @returns A reference to the Store.
|
|
1604
2401
|
* @example
|
|
1605
|
-
* This example sets the contents of a Store from a serialization.
|
|
2402
|
+
* This example sets the tabular contents of a Store from a serialization.
|
|
1606
2403
|
*
|
|
1607
2404
|
* ```js
|
|
1608
2405
|
* const store = createStore();
|
|
1609
|
-
* store.
|
|
2406
|
+
* store.setTablesJson('{"pets": {"fido": {"species": "dog"}}}');
|
|
1610
2407
|
* console.log(store.getTables());
|
|
1611
2408
|
* // -> {pets: {fido: {species: 'dog'}}}
|
|
1612
2409
|
* ```
|
|
1613
2410
|
* @example
|
|
1614
|
-
* This example attempts to set the contents of a Store from an
|
|
2411
|
+
* This example attempts to set the tabular contents of a Store from an
|
|
2412
|
+
* invalid serialization.
|
|
2413
|
+
*
|
|
2414
|
+
* ```js
|
|
2415
|
+
* const store = createStore();
|
|
2416
|
+
* store.setTablesJson('{"pets": {"fido": {');
|
|
2417
|
+
* console.log(store.getTables());
|
|
2418
|
+
* // -> {}
|
|
2419
|
+
* ```
|
|
2420
|
+
* @category Setter
|
|
2421
|
+
* @since v3.0.0
|
|
2422
|
+
*/
|
|
2423
|
+
setTablesJson(tablesJson: Json): Store;
|
|
2424
|
+
|
|
2425
|
+
/**
|
|
2426
|
+
* The setValuesJson method takes a string serialization of all of the Values
|
|
2427
|
+
* in the Store and attempts to update them to those values.
|
|
2428
|
+
*
|
|
2429
|
+
* If the JSON cannot be parsed, this will fail silently. If it can be parsed,
|
|
2430
|
+
* it will then be subject to the same validation rules as the setValues
|
|
2431
|
+
* method (according to the Values type, and matching any ValuesSchema
|
|
2432
|
+
* associated with the Store).
|
|
2433
|
+
*
|
|
2434
|
+
* @param valuesJson A string serialization of all of the Values in the Store.
|
|
2435
|
+
* @returns A reference to the Store.
|
|
2436
|
+
* @example
|
|
2437
|
+
* This example sets the keyed value contents of a Store from a serialization.
|
|
2438
|
+
*
|
|
2439
|
+
* ```js
|
|
2440
|
+
* const store = createStore();
|
|
2441
|
+
* store.setValuesJson('{"open": true}');
|
|
2442
|
+
* console.log(store.getValues());
|
|
2443
|
+
* // -> {open: true}
|
|
2444
|
+
* ```
|
|
2445
|
+
* @example
|
|
2446
|
+
* This example attempts to set the keyed value contents of a Store from an
|
|
2447
|
+
* invalid serialization.
|
|
2448
|
+
*
|
|
2449
|
+
* ```js
|
|
2450
|
+
* const store = createStore();
|
|
2451
|
+
* store.setValuesJson('{"open": false');
|
|
2452
|
+
* console.log(store.getValues());
|
|
2453
|
+
* // -> {}
|
|
2454
|
+
* ```
|
|
2455
|
+
* @category Setter
|
|
2456
|
+
* @since v3.0.0
|
|
2457
|
+
*/
|
|
2458
|
+
setValuesJson(valuesJson: Json): Store;
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* The setJson method takes a string serialization of all of the Tables and
|
|
2462
|
+
* Values in the Store and attempts to update them to those values.
|
|
2463
|
+
*
|
|
2464
|
+
* From v3.0.0 onwards, the serialization should be of an array with two
|
|
2465
|
+
* entries. The first is the Tables object, the second the Values. In previous
|
|
2466
|
+
* versions (before the existence of the Values data structure), it was a sole
|
|
2467
|
+
* object of Tables. For backwards compatibility, if a serialization of a
|
|
2468
|
+
* single object is provided, it will be treated as the Tables type.
|
|
2469
|
+
*
|
|
2470
|
+
* If the JSON cannot be parsed, this will fail silently. If it can be parsed,
|
|
2471
|
+
* it will then be subject to the same validation rules as the setTables
|
|
2472
|
+
* method (according to the Tables type, and matching any TablesSchema
|
|
2473
|
+
* associated with the Store), and the setValues method (according to the
|
|
2474
|
+
* Values type, and matching any ValuesSchema associated with the Store).
|
|
2475
|
+
*
|
|
2476
|
+
* @param tablesAndValuesJson A string serialization of all of the Tables and
|
|
2477
|
+
* Values in the Store.
|
|
2478
|
+
* @returns A reference to the Store.
|
|
2479
|
+
* @example
|
|
2480
|
+
* This example sets the tabular and keyed value contents of a Store from a
|
|
1615
2481
|
* serialization.
|
|
1616
2482
|
*
|
|
1617
2483
|
* ```js
|
|
1618
2484
|
* const store = createStore();
|
|
1619
|
-
* store.setJson('{"pets":{"fido":{');
|
|
2485
|
+
* store.setJson('[{"pets": {"fido": {"species": "dog"}}}, {"open": true}]');
|
|
1620
2486
|
* console.log(store.getTables());
|
|
2487
|
+
* // -> {pets: {fido: {species: 'dog'}}}
|
|
2488
|
+
* console.log(store.getValues());
|
|
2489
|
+
* // -> {open: true}
|
|
2490
|
+
* ```
|
|
2491
|
+
* @example
|
|
2492
|
+
* This example sets the tabular contents of a Store from a
|
|
2493
|
+
* legacy single-object serialization (compatible with v2.x and earlier).
|
|
2494
|
+
*
|
|
2495
|
+
* ```js
|
|
2496
|
+
* const store = createStore();
|
|
2497
|
+
* store.setJson('{"pets": {"fido": {"species": "dog"}}}');
|
|
2498
|
+
* console.log(store.getTables());
|
|
2499
|
+
* // -> {pets: {fido: {species: 'dog'}}}
|
|
2500
|
+
* console.log(store.getValues());
|
|
2501
|
+
* // -> {}
|
|
2502
|
+
* ```
|
|
2503
|
+
* @example
|
|
2504
|
+
* This example attempts to set the the tabular and keyed value contents of a
|
|
2505
|
+
* Store from an invalid serialization.
|
|
2506
|
+
*
|
|
2507
|
+
* ```js
|
|
2508
|
+
* const store = createStore();
|
|
2509
|
+
* store.setValuesJson('[{"pets": {"fido": {"species": "do');
|
|
2510
|
+
* console.log(store.getTables());
|
|
2511
|
+
* // -> {}
|
|
2512
|
+
* console.log(store.getValues());
|
|
1621
2513
|
* // -> {}
|
|
1622
2514
|
* ```
|
|
1623
2515
|
* @category Setter
|
|
1624
2516
|
*/
|
|
1625
|
-
setJson(
|
|
2517
|
+
setJson(tablesAndValuesJson: Json): Store;
|
|
1626
2518
|
|
|
1627
2519
|
/**
|
|
1628
|
-
* The
|
|
2520
|
+
* The setTablesSchema method lets you specify the TablesSchema of the tabular
|
|
2521
|
+
* part of the Store.
|
|
1629
2522
|
*
|
|
1630
2523
|
* Note that this may result in a change to data in the Store, as defaults are
|
|
1631
2524
|
* applied or as invalid Table, Row, or Cell objects are removed. These
|
|
1632
2525
|
* changes will fire any listeners to that data, as expected.
|
|
1633
2526
|
*
|
|
1634
|
-
* When no longer needed, you can also completely remove an existing
|
|
1635
|
-
* with the
|
|
2527
|
+
* When no longer needed, you can also completely remove an existing
|
|
2528
|
+
* TablesSchema with the delTablesSchema method.
|
|
1636
2529
|
*
|
|
1637
|
-
* @param
|
|
2530
|
+
* @param tablesSchema The TablesSchema to be set for the Store.
|
|
1638
2531
|
* @returns A reference to the Store.
|
|
1639
2532
|
* @example
|
|
1640
|
-
* This example sets the
|
|
2533
|
+
* This example sets the TablesSchema of a Store after it has been created.
|
|
2534
|
+
*
|
|
2535
|
+
* ```js
|
|
2536
|
+
* const store = createStore().setTablesSchema({
|
|
2537
|
+
* pets: {
|
|
2538
|
+
* species: {type: 'string'},
|
|
2539
|
+
* sold: {type: 'boolean', default: false},
|
|
2540
|
+
* },
|
|
2541
|
+
* });
|
|
2542
|
+
* store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
|
|
2543
|
+
*
|
|
2544
|
+
* console.log(store.getTables());
|
|
2545
|
+
* // -> {pets: {0: {species: 'dog', sold: false}}}
|
|
2546
|
+
* ```
|
|
2547
|
+
* @category Setter
|
|
2548
|
+
* @since v3.0.0
|
|
2549
|
+
*/
|
|
2550
|
+
setTablesSchema(tablesSchema: TablesSchema): Store;
|
|
2551
|
+
|
|
2552
|
+
/**
|
|
2553
|
+
* The setValuesSchema method lets you specify the ValuesSchema of the keyed
|
|
2554
|
+
* Values part of the Store.
|
|
2555
|
+
*
|
|
2556
|
+
* Note that this may result in a change to data in the Store, as defaults are
|
|
2557
|
+
* applied or as invalid Values are removed. These changes will fire any
|
|
2558
|
+
* listeners to that data, as expected.
|
|
2559
|
+
*
|
|
2560
|
+
* When no longer needed, you can also completely remove an existing
|
|
2561
|
+
* ValuesSchema with the delValuesSchema method.
|
|
2562
|
+
*
|
|
2563
|
+
* @param valuesSchema The ValuesSchema to be set for the Store.
|
|
2564
|
+
* @returns A reference to the Store.
|
|
2565
|
+
* @example
|
|
2566
|
+
* This example sets the ValuesSchema of a Store after it has been created.
|
|
2567
|
+
*
|
|
2568
|
+
* ```js
|
|
2569
|
+
* const store = createStore().setValuesSchema({
|
|
2570
|
+
* open: {type: 'boolean', default: false},
|
|
2571
|
+
* });
|
|
2572
|
+
* store.setValue('open', 'maybe');
|
|
2573
|
+
*
|
|
2574
|
+
* console.log(store.getValues());
|
|
2575
|
+
* // -> {open: false}
|
|
2576
|
+
* ```
|
|
2577
|
+
* @category Setter
|
|
2578
|
+
* @since v3.0.0
|
|
2579
|
+
*/
|
|
2580
|
+
setValuesSchema(valuesSchema: ValuesSchema): Store;
|
|
2581
|
+
|
|
2582
|
+
/**
|
|
2583
|
+
* The setSchema method lets you specify the TablesSchema and ValuesSchema of
|
|
2584
|
+
* the Store.
|
|
2585
|
+
*
|
|
2586
|
+
* Note that this may result in a change to data in the Store, as defaults are
|
|
2587
|
+
* applied or as invalid Table, Row, Cell, or Value objects are removed. These
|
|
2588
|
+
* changes will fire any listeners to that data, as expected.
|
|
2589
|
+
*
|
|
2590
|
+
* From v3.0.0 onwards, this method takes two arguments. The first is the
|
|
2591
|
+
* TablesSchema object, the second the ValuesSchema. In previous versions
|
|
2592
|
+
* (before the existence of the ValuesSchema data structure), only the first
|
|
2593
|
+
* was present. For backwards compatibility the new second parameter is
|
|
2594
|
+
* optional.
|
|
2595
|
+
*
|
|
2596
|
+
* @param tablesSchema The TablesSchema to be set for the Store.
|
|
2597
|
+
* @param valuesSchema The ValuesSchema to be set for the Store.
|
|
2598
|
+
* @returns A reference to the Store.
|
|
2599
|
+
* @example
|
|
2600
|
+
* This example sets the TablesSchema and ValuesSchema of a Store after it has
|
|
2601
|
+
* been created.
|
|
2602
|
+
*
|
|
2603
|
+
* ```js
|
|
2604
|
+
* const store = createStore().setSchema(
|
|
2605
|
+
* {
|
|
2606
|
+
* pets: {
|
|
2607
|
+
* species: {type: 'string'},
|
|
2608
|
+
* sold: {type: 'boolean', default: false},
|
|
2609
|
+
* },
|
|
2610
|
+
* },
|
|
2611
|
+
* {open: {type: 'boolean', default: false}},
|
|
2612
|
+
* );
|
|
2613
|
+
* store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
|
|
2614
|
+
* store.setValue('open', 'maybe');
|
|
2615
|
+
*
|
|
2616
|
+
* console.log(store.getTables());
|
|
2617
|
+
* // -> {pets: {0: {species: 'dog', sold: false}}}
|
|
2618
|
+
* console.log(store.getValues());
|
|
2619
|
+
* // -> {open: false}
|
|
2620
|
+
* ```
|
|
2621
|
+
* @example
|
|
2622
|
+
* This example sets just the TablesSchema of a Store after it has been
|
|
2623
|
+
* created.
|
|
1641
2624
|
*
|
|
1642
2625
|
* ```js
|
|
1643
2626
|
* const store = createStore().setSchema({
|
|
@@ -1647,12 +2630,13 @@ export interface Store {
|
|
|
1647
2630
|
* },
|
|
1648
2631
|
* });
|
|
1649
2632
|
* store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
|
|
2633
|
+
*
|
|
1650
2634
|
* console.log(store.getTables());
|
|
1651
2635
|
* // -> {pets: {0: {species: 'dog', sold: false}}}
|
|
1652
2636
|
* ```
|
|
1653
2637
|
* @category Setter
|
|
1654
2638
|
*/
|
|
1655
|
-
setSchema(
|
|
2639
|
+
setSchema(tablesSchema: TablesSchema, valuesSchema?: ValuesSchema): Store;
|
|
1656
2640
|
|
|
1657
2641
|
/**
|
|
1658
2642
|
* The delTables method lets you remove all of the data in a Store.
|
|
@@ -1721,32 +2705,33 @@ export interface Store {
|
|
|
1721
2705
|
/**
|
|
1722
2706
|
* The delCell method lets you remove a single Cell from a Row.
|
|
1723
2707
|
*
|
|
1724
|
-
* When there is no
|
|
1725
|
-
* in its Row, then that Row will be removed. If, in turn, that is
|
|
1726
|
-
* Row in its Table, then that Table will be removed.
|
|
2708
|
+
* When there is no TablesSchema applied to the Store, then if this is the
|
|
2709
|
+
* last Cell in its Row, then that Row will be removed. If, in turn, that is
|
|
2710
|
+
* the last Row in its Table, then that Table will be removed.
|
|
1727
2711
|
*
|
|
1728
|
-
* If there is a
|
|
1729
|
-
* for this Cell, then deletion will result in it being set back to its
|
|
2712
|
+
* If there is a TablesSchema applied to the Store and it specifies a default
|
|
2713
|
+
* value for this Cell, then deletion will result in it being set back to its
|
|
1730
2714
|
* default value. To override this, use the `forceDel` parameter, as described
|
|
1731
2715
|
* below.
|
|
1732
2716
|
*
|
|
1733
2717
|
* The `forceDel` parameter is an optional flag that is only relevant if a
|
|
1734
|
-
*
|
|
1735
|
-
* deleting a Cell value will normally restore it to the
|
|
1736
|
-
* this flag is set to `true`, the complete removal of the
|
|
1737
|
-
* guaranteed. But since doing do so would result in an
|
|
1738
|
-
* to the
|
|
1739
|
-
* the Table. Therefore, this flag should
|
|
2718
|
+
* TablesSchema provides a default value for this Cell. Under such
|
|
2719
|
+
* circumstances, deleting a Cell value will normally restore it to the
|
|
2720
|
+
* default value. If this flag is set to `true`, the complete removal of the
|
|
2721
|
+
* Cell is instead guaranteed. But since doing do so would result in an
|
|
2722
|
+
* invalid Row (according to the TablesSchema), in fact the whole Row is
|
|
2723
|
+
* deleted to retain the integrity of the Table. Therefore, this flag should
|
|
2724
|
+
* be used with caution.
|
|
1740
2725
|
*
|
|
1741
2726
|
* @param tableId The Id of the Table in the Store.
|
|
1742
2727
|
* @param rowId The Id of the Row in the Table.
|
|
1743
2728
|
* @param cellId The Id of the Cell in the Row.
|
|
1744
2729
|
* @param forceDel An optional flag to indicate that the whole Row should be
|
|
1745
|
-
* deleted, even if a
|
|
1746
|
-
* to `false`.
|
|
2730
|
+
* deleted, even if a TablesSchema provides a default value for this Cell.
|
|
2731
|
+
* Defaults to `false`.
|
|
1747
2732
|
* @returns A reference to the Store.
|
|
1748
2733
|
* @example
|
|
1749
|
-
* This example removes a Cell from a Row without a
|
|
2734
|
+
* This example removes a Cell from a Row without a TablesSchema.
|
|
1750
2735
|
*
|
|
1751
2736
|
* ```js
|
|
1752
2737
|
* const store = createStore().setTables({
|
|
@@ -1758,15 +2743,15 @@ export interface Store {
|
|
|
1758
2743
|
* // -> {pets: {fido: {species: 'dog'}}}
|
|
1759
2744
|
* ```
|
|
1760
2745
|
* @example
|
|
1761
|
-
* This example removes a Cell from a Row with a
|
|
1762
|
-
* value.
|
|
2746
|
+
* This example removes a Cell from a Row with a TablesSchema that defaults
|
|
2747
|
+
* its value.
|
|
1763
2748
|
*
|
|
1764
2749
|
* ```js
|
|
1765
2750
|
* const store = createStore()
|
|
1766
2751
|
* .setTables({
|
|
1767
2752
|
* pets: {fido: {species: 'dog', sold: true}},
|
|
1768
2753
|
* })
|
|
1769
|
-
* .
|
|
2754
|
+
* .setTablesSchema({
|
|
1770
2755
|
* pets: {
|
|
1771
2756
|
* species: {type: 'string'},
|
|
1772
2757
|
* sold: {type: 'boolean', default: false},
|
|
@@ -1778,15 +2763,15 @@ export interface Store {
|
|
|
1778
2763
|
* // -> {pets: {fido: {species: 'dog', sold: false}}}
|
|
1779
2764
|
* ```
|
|
1780
2765
|
* @example
|
|
1781
|
-
* This example removes a Cell from a Row with a
|
|
1782
|
-
* value, but uses the `forceDel` parameter to override it.
|
|
2766
|
+
* This example removes a Cell from a Row with a TablesSchema that defaults
|
|
2767
|
+
* its value, but uses the `forceDel` parameter to override it.
|
|
1783
2768
|
*
|
|
1784
2769
|
* ```js
|
|
1785
2770
|
* const store = createStore()
|
|
1786
2771
|
* .setTables({
|
|
1787
2772
|
* pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
|
|
1788
2773
|
* })
|
|
1789
|
-
* .
|
|
2774
|
+
* .setTablesSchema({
|
|
1790
2775
|
* pets: {
|
|
1791
2776
|
* species: {type: 'string'},
|
|
1792
2777
|
* sold: {type: 'boolean', default: false},
|
|
@@ -1802,19 +2787,147 @@ export interface Store {
|
|
|
1802
2787
|
delCell(tableId: Id, rowId: Id, cellId: Id, forceDel?: boolean): Store;
|
|
1803
2788
|
|
|
1804
2789
|
/**
|
|
1805
|
-
* The
|
|
2790
|
+
* The delValues method lets you remove all the Values from a Store.
|
|
2791
|
+
*
|
|
2792
|
+
* If there is a ValuesSchema applied to the Store and it specifies a default
|
|
2793
|
+
* value for any Value Id, then deletion will result in it being set back to
|
|
2794
|
+
* its default value.
|
|
2795
|
+
*
|
|
2796
|
+
* @returns A reference to the Store.
|
|
2797
|
+
* @example
|
|
2798
|
+
* This example removes all Values from a Store without a ValuesSchema.
|
|
2799
|
+
*
|
|
2800
|
+
* ```js
|
|
2801
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
2802
|
+
* store.delValues();
|
|
2803
|
+
*
|
|
2804
|
+
* console.log(store.getValues());
|
|
2805
|
+
* // -> {}
|
|
2806
|
+
* ```
|
|
2807
|
+
* @example
|
|
2808
|
+
* This example removes all Values from a Store with a ValuesSchema that
|
|
2809
|
+
* defaults one of its values.
|
|
2810
|
+
*
|
|
2811
|
+
* ```js
|
|
2812
|
+
* const store = createStore()
|
|
2813
|
+
* .setValues({open: true, employees: 3})
|
|
2814
|
+
* .setValuesSchema({
|
|
2815
|
+
* open: {type: 'boolean', default: false},
|
|
2816
|
+
* employees: {type: 'number'},
|
|
2817
|
+
* });
|
|
2818
|
+
* store.delValues();
|
|
2819
|
+
*
|
|
2820
|
+
* console.log(store.getValues());
|
|
2821
|
+
* // -> {open: false}
|
|
2822
|
+
* ```
|
|
2823
|
+
* @category Deleter
|
|
2824
|
+
* @since v3.0.0
|
|
2825
|
+
*/
|
|
2826
|
+
delValues(): Store;
|
|
2827
|
+
|
|
2828
|
+
/**
|
|
2829
|
+
* The delValue method lets you remove a single Value from a Store.
|
|
2830
|
+
*
|
|
2831
|
+
* If there is a ValuesSchema applied to the Store and it specifies a default
|
|
2832
|
+
* value for this Value Id, then deletion will result in it being set back to
|
|
2833
|
+
* its default value.
|
|
2834
|
+
*
|
|
2835
|
+
* @param valueId The Id of the Value in the Row.
|
|
2836
|
+
* @returns A reference to the Store.
|
|
2837
|
+
* @example
|
|
2838
|
+
* This example removes a Value from a Store without a ValuesSchema.
|
|
2839
|
+
*
|
|
2840
|
+
* ```js
|
|
2841
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
2842
|
+
* store.delValue('employees');
|
|
2843
|
+
*
|
|
2844
|
+
* console.log(store.getValues());
|
|
2845
|
+
* // -> {open: true}
|
|
2846
|
+
* ```
|
|
2847
|
+
* @example
|
|
2848
|
+
* This example removes a Value from a Store with a ValuesSchema that defaults
|
|
2849
|
+
* its value.
|
|
2850
|
+
*
|
|
2851
|
+
* ```js
|
|
2852
|
+
* const store = createStore()
|
|
2853
|
+
* .setValues({open: true, employees: 3})
|
|
2854
|
+
* .setValuesSchema({
|
|
2855
|
+
* open: {type: 'boolean', default: false},
|
|
2856
|
+
* employees: {type: 'number'},
|
|
2857
|
+
* });
|
|
2858
|
+
* store.delValue('open');
|
|
2859
|
+
*
|
|
2860
|
+
* console.log(store.getValues());
|
|
2861
|
+
* // -> {open: false, employees: 3}
|
|
2862
|
+
* ```
|
|
2863
|
+
* @category Deleter
|
|
2864
|
+
* @since v3.0.0
|
|
2865
|
+
*/
|
|
2866
|
+
delValue(valueId: Id): Store;
|
|
2867
|
+
|
|
2868
|
+
/**
|
|
2869
|
+
* The delTablesSchema method lets you remove the TablesSchema of the Store.
|
|
2870
|
+
*
|
|
2871
|
+
* @returns A reference to the Store.
|
|
2872
|
+
* @example
|
|
2873
|
+
* This example removes the TablesSchema of a Store.
|
|
2874
|
+
*
|
|
2875
|
+
* ```js
|
|
2876
|
+
* const store = createStore().setTablesSchema({
|
|
2877
|
+
* pets: {species: {type: 'string'}},
|
|
2878
|
+
* });
|
|
2879
|
+
* store.delTablesSchema();
|
|
2880
|
+
* console.log(store.getTablesSchemaJson());
|
|
2881
|
+
* // -> '{}'
|
|
2882
|
+
* ```
|
|
2883
|
+
* @category Deleter
|
|
2884
|
+
*/
|
|
2885
|
+
delTablesSchema(): Store;
|
|
2886
|
+
|
|
2887
|
+
/**
|
|
2888
|
+
* The delValuesSchema method lets you remove the ValuesSchema of the Store.
|
|
1806
2889
|
*
|
|
1807
2890
|
* @returns A reference to the Store.
|
|
1808
2891
|
* @example
|
|
1809
|
-
* This example removes the
|
|
2892
|
+
* This example removes the ValuesSchema of a Store.
|
|
1810
2893
|
*
|
|
1811
2894
|
* ```js
|
|
1812
|
-
* const store = createStore().
|
|
2895
|
+
* const store = createStore().setValuesSchema({
|
|
2896
|
+
* sold: {type: 'boolean', default: false},
|
|
2897
|
+
* });
|
|
2898
|
+
* store.delValuesSchema();
|
|
2899
|
+
* console.log(store.getValuesSchemaJson());
|
|
2900
|
+
* // -> '{}'
|
|
2901
|
+
* ```
|
|
2902
|
+
* @category Deleter
|
|
2903
|
+
* @since v3.0.0
|
|
2904
|
+
*/
|
|
2905
|
+
delValuesSchema(): Store;
|
|
2906
|
+
|
|
2907
|
+
/**
|
|
2908
|
+
* The delSchema method lets you remove both the TablesSchema and ValuesSchema
|
|
2909
|
+
* of the Store.
|
|
2910
|
+
*
|
|
2911
|
+
* Prior to v3.0.0, this method removed the TablesSchema only.
|
|
2912
|
+
*
|
|
2913
|
+
* @returns A reference to the Store.
|
|
2914
|
+
* @example
|
|
2915
|
+
* This example removes the TablesSchema and ValuesSchema of a Store.
|
|
2916
|
+
*
|
|
2917
|
+
* ```js
|
|
2918
|
+
* const store = createStore()
|
|
2919
|
+
* .setTablesSchema({
|
|
2920
|
+
* pets: {species: {type: 'string'}},
|
|
2921
|
+
* })
|
|
2922
|
+
* .setValuesSchema({
|
|
2923
|
+
* sold: {type: 'boolean', default: false},
|
|
2924
|
+
* });
|
|
1813
2925
|
* store.delSchema();
|
|
1814
2926
|
* console.log(store.getSchemaJson());
|
|
1815
|
-
* // -> '{}'
|
|
2927
|
+
* // -> '[{},{}]'
|
|
1816
2928
|
* ```
|
|
1817
2929
|
* @category Deleter
|
|
2930
|
+
* @since v3.0.0
|
|
1818
2931
|
*/
|
|
1819
2932
|
delSchema(): Store;
|
|
1820
2933
|
|
|
@@ -1840,11 +2953,12 @@ export interface Store {
|
|
|
1840
2953
|
* Transactions can be nested. Relevant listeners will be called only when the
|
|
1841
2954
|
* outermost one completes.
|
|
1842
2955
|
*
|
|
1843
|
-
* The second, optional parameter, `doRollback` is a callback that
|
|
1844
|
-
* to rollback the transaction if it did not complete to your
|
|
1845
|
-
* is called with `changedCells
|
|
1846
|
-
*
|
|
1847
|
-
*
|
|
2956
|
+
* The second, optional parameter, `doRollback` is a DoRollback callback that
|
|
2957
|
+
* you can use to rollback the transaction if it did not complete to your
|
|
2958
|
+
* satisfaction. It is called with `changedCells`, `invalidCells`,
|
|
2959
|
+
* `changedValues`, and `invalidValues` parameters, which inform you of the
|
|
2960
|
+
* net changes that have been made during the transaction, and any invalid
|
|
2961
|
+
* attempts to do so, respectively.
|
|
1848
2962
|
*
|
|
1849
2963
|
* @param actions The function to be executed as a transaction.
|
|
1850
2964
|
* @param doRollback An optional callback that should return `true` if you
|
|
@@ -1859,15 +2973,17 @@ export interface Store {
|
|
|
1859
2973
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
1860
2974
|
* store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
|
|
1861
2975
|
*
|
|
1862
|
-
* store
|
|
1863
|
-
*
|
|
2976
|
+
* store
|
|
2977
|
+
* .setCell('pets', 'fido', 'color', 'brown')
|
|
2978
|
+
* .setCell('pets', 'fido', 'sold', false);
|
|
1864
2979
|
* // -> 'Fido changed'
|
|
1865
2980
|
* // -> 'Fido changed'
|
|
1866
2981
|
*
|
|
1867
|
-
* store.transaction(() =>
|
|
1868
|
-
* store
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
2982
|
+
* store.transaction(() =>
|
|
2983
|
+
* store
|
|
2984
|
+
* .setCell('pets', 'fido', 'color', 'walnut')
|
|
2985
|
+
* .setCell('pets', 'fido', 'sold', true),
|
|
2986
|
+
* );
|
|
1871
2987
|
* // -> 'Fido changed'
|
|
1872
2988
|
* ```
|
|
1873
2989
|
* @example
|
|
@@ -1884,60 +3000,64 @@ export interface Store {
|
|
|
1884
3000
|
* (store, tableId, rowId, cellId, newCell) => console.log(newCell),
|
|
1885
3001
|
* );
|
|
1886
3002
|
*
|
|
1887
|
-
* store.transaction(() =>
|
|
1888
|
-
* store
|
|
1889
|
-
*
|
|
1890
|
-
*
|
|
1891
|
-
*
|
|
3003
|
+
* store.transaction(() =>
|
|
3004
|
+
* store
|
|
3005
|
+
* .setCell('pets', 'fido', 'color', 'black')
|
|
3006
|
+
* .setCell('pets', 'fido', 'color', 'brown')
|
|
3007
|
+
* .setCell('pets', 'fido', 'color', 'walnut'),
|
|
3008
|
+
* );
|
|
1892
3009
|
* // -> 'walnut'
|
|
1893
3010
|
*
|
|
1894
|
-
* store.transaction(() =>
|
|
1895
|
-
* store
|
|
1896
|
-
*
|
|
1897
|
-
*
|
|
3011
|
+
* store.transaction(() =>
|
|
3012
|
+
* store
|
|
3013
|
+
* .setCell('pets', 'fido', 'color', 'black')
|
|
3014
|
+
* .setCell('pets', 'fido', 'color', 'walnut'),
|
|
3015
|
+
* );
|
|
1898
3016
|
* // -> undefined
|
|
1899
3017
|
* // No net change during the transaction, so the listener is not called.
|
|
1900
3018
|
* ```
|
|
1901
3019
|
* @example
|
|
1902
|
-
* This example makes multiple changes to the Store, including some attempts
|
|
1903
|
-
* to update a Cell with invalid values. The `doRollback` callback
|
|
1904
|
-
* information about the changes and invalid attempts, and then
|
|
1905
|
-
* the transaction should be rolled back to its original state.
|
|
3020
|
+
* This example makes multiple changes to the Store, including some attempts
|
|
3021
|
+
* to update a Cell and Value with invalid values. The `doRollback` callback
|
|
3022
|
+
* receives information about the changes and invalid attempts, and then
|
|
3023
|
+
* judges that the transaction should be rolled back to its original state.
|
|
1906
3024
|
*
|
|
1907
3025
|
* ```js
|
|
1908
|
-
* const store = createStore()
|
|
1909
|
-
* pets: {fido: {species: 'dog', color: 'brown'}}
|
|
1910
|
-
* });
|
|
3026
|
+
* const store = createStore()
|
|
3027
|
+
* .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
|
|
3028
|
+
* .setValues({open: true});
|
|
1911
3029
|
*
|
|
1912
3030
|
* store.transaction(
|
|
1913
|
-
* () =>
|
|
1914
|
-
* store
|
|
1915
|
-
*
|
|
1916
|
-
*
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
3031
|
+
* () =>
|
|
3032
|
+
* store
|
|
3033
|
+
* .setCell('pets', 'fido', 'color', 'black')
|
|
3034
|
+
* .setCell('pets', 'fido', 'eyes', ['left', 'right'])
|
|
3035
|
+
* .setCell('pets', 'fido', 'info', {sold: null})
|
|
3036
|
+
* .setValue('open', false)
|
|
3037
|
+
* .setValue('employees', ['alice', 'bob']),
|
|
3038
|
+
* (changedCells, invalidCells, changedValues, invalidValues) => {
|
|
1919
3039
|
* console.log(store.getTables());
|
|
1920
|
-
* // -> {pets: {fido: {species: 'dog', color: 'black'}}}
|
|
1921
3040
|
* console.log(changedCells);
|
|
1922
|
-
* // -> {pets: {fido: {color: ['brown', 'black']}}}
|
|
1923
3041
|
* console.log(invalidCells);
|
|
1924
|
-
*
|
|
3042
|
+
* console.log(changedValues);
|
|
3043
|
+
* console.log(invalidValues);
|
|
1925
3044
|
* return invalidCells['pets'] != null;
|
|
1926
3045
|
* },
|
|
1927
3046
|
* );
|
|
3047
|
+
* // -> {pets: {fido: {species: 'dog', color: 'black'}}}
|
|
3048
|
+
* // -> {pets: {fido: {color: ['brown', 'black']}}}
|
|
3049
|
+
* // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
|
|
3050
|
+
* // -> {open: [true, false]}
|
|
3051
|
+
* // -> {employees: [['alice', 'bob']]}
|
|
1928
3052
|
*
|
|
1929
3053
|
* console.log(store.getTables());
|
|
1930
3054
|
* // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
|
|
3055
|
+
* console.log(store.getValues());
|
|
3056
|
+
* // -> {open: true}
|
|
1931
3057
|
* ```
|
|
1932
3058
|
* @category Transaction
|
|
1933
3059
|
*/
|
|
1934
|
-
transaction<Return>(
|
|
1935
|
-
actions: () => Return,
|
|
1936
|
-
doRollback?: (
|
|
1937
|
-
changedCells: ChangedCells,
|
|
1938
|
-
invalidCells: InvalidCells,
|
|
1939
|
-
) => boolean,
|
|
1940
|
-
): Return;
|
|
3060
|
+
transaction<Return>(actions: () => Return, doRollback?: DoRollback): Return;
|
|
1941
3061
|
|
|
1942
3062
|
/**
|
|
1943
3063
|
* The startTransaction method allows you to explicitly start a transaction
|
|
@@ -1972,15 +3092,17 @@ export interface Store {
|
|
|
1972
3092
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
1973
3093
|
* store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
|
|
1974
3094
|
*
|
|
1975
|
-
* store
|
|
1976
|
-
*
|
|
3095
|
+
* store
|
|
3096
|
+
* .setCell('pets', 'fido', 'color', 'brown')
|
|
3097
|
+
* .setCell('pets', 'fido', 'sold', false);
|
|
1977
3098
|
* // -> 'Fido changed'
|
|
1978
3099
|
* // -> 'Fido changed'
|
|
1979
3100
|
*
|
|
1980
|
-
* store
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
3101
|
+
* store
|
|
3102
|
+
* .startTransaction()
|
|
3103
|
+
* .setCell('pets', 'fido', 'color', 'walnut')
|
|
3104
|
+
* .setCell('pets', 'fido', 'sold', true)
|
|
3105
|
+
* .finishTransaction();
|
|
1984
3106
|
* // -> 'Fido changed'
|
|
1985
3107
|
* ```
|
|
1986
3108
|
* @category Transaction
|
|
@@ -2010,6 +3132,13 @@ export interface Store {
|
|
|
2010
3132
|
* been a corresponding startTransaction method that this completes, of
|
|
2011
3133
|
* course, otherwise this function has no effect.
|
|
2012
3134
|
*
|
|
3135
|
+
* The optional parameter, `doRollback` is a DoRollback callback that
|
|
3136
|
+
* you can use to rollback the transaction if it did not complete to your
|
|
3137
|
+
* satisfaction. It is called with `changedCells`, `invalidCells`,
|
|
3138
|
+
* `changedValues`, and `invalidValues` parameters, which inform you of the
|
|
3139
|
+
* net changes that have been made during the transaction, and any invalid
|
|
3140
|
+
* attempts to do so, respectively.
|
|
3141
|
+
*
|
|
2013
3142
|
* @param doRollback An optional callback that should return `true` if you
|
|
2014
3143
|
* want to rollback the transaction at the end.
|
|
2015
3144
|
* @returns A reference to the Store.
|
|
@@ -2022,15 +3151,17 @@ export interface Store {
|
|
|
2022
3151
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
2023
3152
|
* store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
|
|
2024
3153
|
*
|
|
2025
|
-
* store
|
|
2026
|
-
*
|
|
3154
|
+
* store
|
|
3155
|
+
* .setCell('pets', 'fido', 'color', 'brown')
|
|
3156
|
+
* .setCell('pets', 'fido', 'sold', false);
|
|
2027
3157
|
* // -> 'Fido changed'
|
|
2028
3158
|
* // -> 'Fido changed'
|
|
2029
3159
|
*
|
|
2030
|
-
* store
|
|
2031
|
-
*
|
|
2032
|
-
*
|
|
2033
|
-
*
|
|
3160
|
+
* store
|
|
3161
|
+
* .startTransaction()
|
|
3162
|
+
* .setCell('pets', 'fido', 'color', 'walnut')
|
|
3163
|
+
* .setCell('pets', 'fido', 'sold', true)
|
|
3164
|
+
* .finishTransaction();
|
|
2034
3165
|
* // -> 'Fido changed'
|
|
2035
3166
|
* ```
|
|
2036
3167
|
* @example
|
|
@@ -2040,36 +3171,42 @@ export interface Store {
|
|
|
2040
3171
|
* the transaction should be rolled back to its original state.
|
|
2041
3172
|
*
|
|
2042
3173
|
* ```js
|
|
2043
|
-
* const store = createStore()
|
|
2044
|
-
* pets: {fido: {species: 'dog', color: 'brown'}}
|
|
2045
|
-
* });
|
|
2046
|
-
*
|
|
2047
|
-
* store
|
|
2048
|
-
*
|
|
2049
|
-
*
|
|
2050
|
-
*
|
|
2051
|
-
*
|
|
2052
|
-
*
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2056
|
-
*
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2059
|
-
*
|
|
3174
|
+
* const store = createStore()
|
|
3175
|
+
* .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
|
|
3176
|
+
* .setValues({open: true});
|
|
3177
|
+
*
|
|
3178
|
+
* store
|
|
3179
|
+
* .startTransaction()
|
|
3180
|
+
* .setCell('pets', 'fido', 'color', 'black')
|
|
3181
|
+
* .setCell('pets', 'fido', 'eyes', ['left', 'right'])
|
|
3182
|
+
* .setCell('pets', 'fido', 'info', {sold: null})
|
|
3183
|
+
* .setValue('open', false)
|
|
3184
|
+
* .setValue('employees', ['alice', 'bob'])
|
|
3185
|
+
* .finishTransaction(
|
|
3186
|
+
* (changedCells, invalidCells, changedValues, invalidValues) => {
|
|
3187
|
+
* console.log(store.getTables());
|
|
3188
|
+
* console.log(changedCells);
|
|
3189
|
+
* console.log(invalidCells);
|
|
3190
|
+
* console.log(changedValues);
|
|
3191
|
+
* console.log(invalidValues);
|
|
3192
|
+
* return invalidCells['pets'] != null;
|
|
3193
|
+
* },
|
|
3194
|
+
* );
|
|
3195
|
+
* // -> {pets: {fido: {species: 'dog', color: 'black'}}}
|
|
3196
|
+
* // -> {pets: {fido: {color: ['brown', 'black']}}}
|
|
3197
|
+
* // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
|
|
3198
|
+
* // -> {open: [true, false]}
|
|
3199
|
+
* // -> {employees: [['alice', 'bob']]}
|
|
2060
3200
|
*
|
|
2061
3201
|
* console.log(store.getTables());
|
|
2062
3202
|
* // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
|
|
3203
|
+
* console.log(store.getValues());
|
|
3204
|
+
* // -> {open: true}
|
|
2063
3205
|
* ```
|
|
2064
3206
|
* @category Transaction
|
|
2065
3207
|
* @since v1.3.0
|
|
2066
3208
|
*/
|
|
2067
|
-
finishTransaction(
|
|
2068
|
-
doRollback?: (
|
|
2069
|
-
changedCells: ChangedCells,
|
|
2070
|
-
invalidCells: InvalidCells,
|
|
2071
|
-
) => boolean,
|
|
2072
|
-
): Store;
|
|
3209
|
+
finishTransaction(doRollback?: DoRollback): Store;
|
|
2073
3210
|
|
|
2074
3211
|
/**
|
|
2075
3212
|
* The forEachTable method takes a function that it will then call for each
|
|
@@ -2167,6 +3304,31 @@ export interface Store {
|
|
|
2167
3304
|
*/
|
|
2168
3305
|
forEachCell(tableId: Id, rowId: Id, cellCallback: CellCallback): void;
|
|
2169
3306
|
|
|
3307
|
+
/**
|
|
3308
|
+
* The forEachValue method takes a function that it will then call for each
|
|
3309
|
+
* Value in a Store.
|
|
3310
|
+
*
|
|
3311
|
+
* This method is useful for iterating over the Value structure of the Store
|
|
3312
|
+
* in a functional style. The `valueCallback` parameter is a ValueCallback
|
|
3313
|
+
* function that will be called with the Id and value of each Value.
|
|
3314
|
+
*
|
|
3315
|
+
* @param valueCallback The function that should be called for every Value.
|
|
3316
|
+
* @example
|
|
3317
|
+
* This example iterates over each Value in a Store, and lists its value.
|
|
3318
|
+
*
|
|
3319
|
+
* ```js
|
|
3320
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
3321
|
+
* store.forEachValue((valueId, value) => {
|
|
3322
|
+
* console.log(`${valueId}: ${value}`);
|
|
3323
|
+
* });
|
|
3324
|
+
* // -> 'open: true'
|
|
3325
|
+
* // -> 'employees: 3'
|
|
3326
|
+
* ```
|
|
3327
|
+
* @category Iterator
|
|
3328
|
+
* @since v3.0.0
|
|
3329
|
+
*/
|
|
3330
|
+
forEachValue(valueCallback: ValueCallback): void;
|
|
3331
|
+
|
|
2170
3332
|
/**
|
|
2171
3333
|
* The addTablesListener method registers a listener function with the Store
|
|
2172
3334
|
* that will be called whenever data in the Store changes.
|
|
@@ -2873,76 +4035,314 @@ export interface Store {
|
|
|
2873
4035
|
* store.delListener(listenerId);
|
|
2874
4036
|
* ```
|
|
2875
4037
|
* @example
|
|
2876
|
-
* This example registers a listener that responds to any change to the Cell
|
|
2877
|
-
* Ids of any Row.
|
|
4038
|
+
* This example registers a listener that responds to any change to the Cell
|
|
4039
|
+
* Ids of any Row.
|
|
4040
|
+
*
|
|
4041
|
+
* ```js
|
|
4042
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
4043
|
+
* const listenerId = store.addCellIdsListener(
|
|
4044
|
+
* null,
|
|
4045
|
+
* null,
|
|
4046
|
+
* (store, tableId, rowId) => {
|
|
4047
|
+
* console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
|
|
4048
|
+
* console.log(store.getCellIds(tableId, rowId));
|
|
4049
|
+
* },
|
|
4050
|
+
* );
|
|
4051
|
+
*
|
|
4052
|
+
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
4053
|
+
* // -> 'Cell Ids for fido row in pets table changed'
|
|
4054
|
+
* // -> ['species', 'color']
|
|
4055
|
+
* store.setCell('species', 'dog', 'price', 5);
|
|
4056
|
+
* // -> 'Cell Ids for dog row in species table changed'
|
|
4057
|
+
* // -> ['price']
|
|
4058
|
+
*
|
|
4059
|
+
* store.delListener(listenerId);
|
|
4060
|
+
* ```
|
|
4061
|
+
* @example
|
|
4062
|
+
* This example registers a listener that responds to any change to the Cell
|
|
4063
|
+
* Ids of a specific Row, and which also mutates the Store itself.
|
|
4064
|
+
*
|
|
4065
|
+
* ```js
|
|
4066
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
4067
|
+
* const listenerId = store.addCellIdsListener(
|
|
4068
|
+
* 'pets',
|
|
4069
|
+
* 'fido',
|
|
4070
|
+
* (store, tableId, rowId) =>
|
|
4071
|
+
* store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
|
|
4072
|
+
* true, // mutator
|
|
4073
|
+
* );
|
|
4074
|
+
*
|
|
4075
|
+
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
4076
|
+
* console.log(store.getTable('meta'));
|
|
4077
|
+
* // -> {update: {pets_fido: true}}
|
|
4078
|
+
*
|
|
4079
|
+
* store.delListener(listenerId);
|
|
4080
|
+
* ```
|
|
4081
|
+
* @category Listener
|
|
4082
|
+
*/
|
|
4083
|
+
addCellIdsListener(
|
|
4084
|
+
tableId: IdOrNull,
|
|
4085
|
+
rowId: IdOrNull,
|
|
4086
|
+
listener: CellIdsListener,
|
|
4087
|
+
mutator?: boolean,
|
|
4088
|
+
): Id;
|
|
4089
|
+
|
|
4090
|
+
/**
|
|
4091
|
+
* The addCellListener method registers a listener function with the Store
|
|
4092
|
+
* that will be called whenever data in a Cell changes.
|
|
4093
|
+
*
|
|
4094
|
+
* The provided listener is a CellListener function, and will be called with a
|
|
4095
|
+
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
4096
|
+
* that changed, the Id of the Cell that changed, the new Cell value, the old
|
|
4097
|
+
* Cell value, and a GetCellChange function in case you need to inspect any
|
|
4098
|
+
* changes that occurred.
|
|
4099
|
+
*
|
|
4100
|
+
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
4101
|
+
* and Cell Id as the method's first three parameters) or changes to any Cell
|
|
4102
|
+
* (by providing `null` wildcards).
|
|
4103
|
+
*
|
|
4104
|
+
* All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
|
|
4105
|
+
* be wildcarded with `null`. You can listen to a specific Cell in a specific
|
|
4106
|
+
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
4107
|
+
* every other combination of wildcards.
|
|
4108
|
+
*
|
|
4109
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4110
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4111
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4112
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4113
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4114
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4115
|
+
* though they will fire non-mutator listeners.
|
|
4116
|
+
*
|
|
4117
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
4118
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
4119
|
+
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
4120
|
+
* @param listener The function that will be called whenever data in the
|
|
4121
|
+
* matching Cell changes.
|
|
4122
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4123
|
+
* Store data.
|
|
4124
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4125
|
+
* explicitly, or to remove it.
|
|
4126
|
+
* @example
|
|
4127
|
+
* This example registers a listener that responds to any changes to a
|
|
4128
|
+
* specific Cell.
|
|
4129
|
+
*
|
|
4130
|
+
* ```js
|
|
4131
|
+
* const store = createStore().setTables({
|
|
4132
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4133
|
+
* });
|
|
4134
|
+
* const listenerId = store.addCellListener(
|
|
4135
|
+
* 'pets',
|
|
4136
|
+
* 'fido',
|
|
4137
|
+
* 'color',
|
|
4138
|
+
* (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
|
|
4139
|
+
* console.log('color cell in fido row in pets table changed');
|
|
4140
|
+
* console.log([oldCell, newCell]);
|
|
4141
|
+
* console.log(getCellChange('pets', 'fido', 'color'));
|
|
4142
|
+
* },
|
|
4143
|
+
* );
|
|
4144
|
+
*
|
|
4145
|
+
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
4146
|
+
* // -> 'color cell in fido row in pets table changed'
|
|
4147
|
+
* // -> ['brown', 'walnut']
|
|
4148
|
+
* // -> [true, 'brown', 'walnut']
|
|
4149
|
+
*
|
|
4150
|
+
* store.delListener(listenerId);
|
|
4151
|
+
* ```
|
|
4152
|
+
* @example
|
|
4153
|
+
* This example registers a listener that responds to any changes to any Cell.
|
|
4154
|
+
*
|
|
4155
|
+
* ```js
|
|
4156
|
+
* const store = createStore().setTables({
|
|
4157
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4158
|
+
* });
|
|
4159
|
+
* const listenerId = store.addCellListener(
|
|
4160
|
+
* null,
|
|
4161
|
+
* null,
|
|
4162
|
+
* null,
|
|
4163
|
+
* (store, tableId, rowId, cellId) => {
|
|
4164
|
+
* console.log(
|
|
4165
|
+
* `${cellId} cell in ${rowId} row in ${tableId} table changed`,
|
|
4166
|
+
* );
|
|
4167
|
+
* },
|
|
4168
|
+
* );
|
|
4169
|
+
*
|
|
4170
|
+
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
4171
|
+
* // -> 'color cell in fido row in pets table changed'
|
|
4172
|
+
* store.setTable('species', {dog: {price: 5}});
|
|
4173
|
+
* // -> 'price cell in dog row in species table changed'
|
|
4174
|
+
*
|
|
4175
|
+
* store.delListener(listenerId);
|
|
4176
|
+
* ```
|
|
4177
|
+
* @example
|
|
4178
|
+
* This example registers a listener that responds to any changes to a
|
|
4179
|
+
* specific Cell, and which also mutates the Store itself.
|
|
4180
|
+
*
|
|
4181
|
+
* ```js
|
|
4182
|
+
* const store = createStore().setTables({
|
|
4183
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4184
|
+
* });
|
|
4185
|
+
* const listenerId = store.addCellListener(
|
|
4186
|
+
* 'pets',
|
|
4187
|
+
* 'fido',
|
|
4188
|
+
* 'color',
|
|
4189
|
+
* (store, tableId, rowId, cellId) =>
|
|
4190
|
+
* store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
|
|
4191
|
+
* true,
|
|
4192
|
+
* );
|
|
4193
|
+
*
|
|
4194
|
+
* store.delCell('pets', 'fido', 'color');
|
|
4195
|
+
* console.log(store.getTable('meta'));
|
|
4196
|
+
* // -> {update: {pets_fido_color: true}}
|
|
4197
|
+
*
|
|
4198
|
+
* store.delListener(listenerId);
|
|
4199
|
+
* ```
|
|
4200
|
+
* @category Listener
|
|
4201
|
+
*/
|
|
4202
|
+
addCellListener(
|
|
4203
|
+
tableId: IdOrNull,
|
|
4204
|
+
rowId: IdOrNull,
|
|
4205
|
+
cellId: IdOrNull,
|
|
4206
|
+
listener: CellListener,
|
|
4207
|
+
mutator?: boolean,
|
|
4208
|
+
): Id;
|
|
4209
|
+
|
|
4210
|
+
/**
|
|
4211
|
+
* The addValuesListener method registers a listener function with the Store
|
|
4212
|
+
* that will be called whenever the Values change.
|
|
4213
|
+
*
|
|
4214
|
+
* The provided listener is a ValuesListener function, and will be called with
|
|
4215
|
+
* a reference to the Store and a GetValueChange function in case you need to
|
|
4216
|
+
* inspect any changes that occurred.
|
|
4217
|
+
*
|
|
4218
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4219
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4220
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4221
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4222
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4223
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4224
|
+
* though they will fire non-mutator listeners.
|
|
4225
|
+
*
|
|
4226
|
+
* @param listener The function that will be called whenever data in the
|
|
4227
|
+
* Values changes.
|
|
4228
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4229
|
+
* Store data.
|
|
4230
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4231
|
+
* explicitly, or to remove it.
|
|
4232
|
+
* @example
|
|
4233
|
+
* This example registers a listener that responds to any changes to the
|
|
4234
|
+
* Store's Values.
|
|
4235
|
+
*
|
|
4236
|
+
* ```js
|
|
4237
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
4238
|
+
* const listenerId = store.addValuesListener((store, getValueChange) => {
|
|
4239
|
+
* console.log('values changed');
|
|
4240
|
+
* console.log(getValueChange('employees'));
|
|
4241
|
+
* });
|
|
4242
|
+
*
|
|
4243
|
+
* store.setValue('employees', 4);
|
|
4244
|
+
* // -> 'values changed'
|
|
4245
|
+
* // -> [true, 3, 4]
|
|
4246
|
+
*
|
|
4247
|
+
* store.delListener(listenerId);
|
|
4248
|
+
* ```
|
|
4249
|
+
* @example
|
|
4250
|
+
* This example registers a listener that responds to any changes to the
|
|
4251
|
+
* Store's Values, and which also mutates the Store itself.
|
|
4252
|
+
*
|
|
4253
|
+
* ```js
|
|
4254
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
4255
|
+
* const listenerId = store.addValuesListener(
|
|
4256
|
+
* (store, getValueChange) => store.setValue('updated', true),
|
|
4257
|
+
* true,
|
|
4258
|
+
* );
|
|
4259
|
+
*
|
|
4260
|
+
* store.setValue('employees', 4);
|
|
4261
|
+
* console.log(store.getValues());
|
|
4262
|
+
* // -> {open: true, employees: 4, updated: true}
|
|
4263
|
+
*
|
|
4264
|
+
* store.delListener(listenerId);
|
|
4265
|
+
* ```
|
|
4266
|
+
* @category Listener
|
|
4267
|
+
* @since v3.0.0
|
|
4268
|
+
*/
|
|
4269
|
+
addValuesListener(listener: ValuesListener, mutator?: boolean): Id;
|
|
4270
|
+
|
|
4271
|
+
/**
|
|
4272
|
+
* The addValueIdsListener method registers a listener function with the Store
|
|
4273
|
+
* that will be called whenever the Value Ids in a Store change.
|
|
4274
|
+
*
|
|
4275
|
+
* The provided listener is a ValueIdsListener function, and will be called
|
|
4276
|
+
* with a reference to the Store.
|
|
4277
|
+
*
|
|
4278
|
+
* By default, such a listener is only called when a Value is added or
|
|
4279
|
+
* removed. To listen to all changes in the Values, use the addValuesListener
|
|
4280
|
+
* method.
|
|
4281
|
+
*
|
|
4282
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4283
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4284
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4285
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4286
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4287
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4288
|
+
* though they will fire non-mutator listeners.
|
|
4289
|
+
*
|
|
4290
|
+
* @param listener The function that will be called whenever the Value Ids in
|
|
4291
|
+
* the Store change.
|
|
4292
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4293
|
+
* Store data.
|
|
4294
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4295
|
+
* explicitly, or to remove it.
|
|
4296
|
+
* @example
|
|
4297
|
+
* This example registers a listener that responds to any change to the Value
|
|
4298
|
+
* Ids.
|
|
2878
4299
|
*
|
|
2879
4300
|
* ```js
|
|
2880
|
-
* const store = createStore().
|
|
2881
|
-
* const listenerId = store.
|
|
2882
|
-
*
|
|
2883
|
-
*
|
|
2884
|
-
*
|
|
2885
|
-
* console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
|
|
2886
|
-
* console.log(store.getCellIds(tableId, rowId));
|
|
2887
|
-
* },
|
|
2888
|
-
* );
|
|
4301
|
+
* const store = createStore().setValues({open: true});
|
|
4302
|
+
* const listenerId = store.addValueIdsListener((store) => {
|
|
4303
|
+
* console.log('Value Ids changed');
|
|
4304
|
+
* console.log(store.getValueIds());
|
|
4305
|
+
* });
|
|
2889
4306
|
*
|
|
2890
|
-
* store.
|
|
2891
|
-
* // -> '
|
|
2892
|
-
* // -> ['
|
|
2893
|
-
* store.setCell('species', 'dog', 'price', 5);
|
|
2894
|
-
* // -> 'Cell Ids for dog row in species table changed'
|
|
2895
|
-
* // -> ['price']
|
|
4307
|
+
* store.setValue('employees', 3);
|
|
4308
|
+
* // -> 'Value Ids changed'
|
|
4309
|
+
* // -> ['open', 'employees']
|
|
2896
4310
|
*
|
|
2897
4311
|
* store.delListener(listenerId);
|
|
2898
4312
|
* ```
|
|
2899
4313
|
* @example
|
|
2900
|
-
* This example registers a listener that responds to any change to the
|
|
2901
|
-
* Ids
|
|
4314
|
+
* This example registers a listener that responds to any change to the Value
|
|
4315
|
+
* Ids, and which also mutates the Store itself.
|
|
2902
4316
|
*
|
|
2903
4317
|
* ```js
|
|
2904
|
-
* const store = createStore().
|
|
2905
|
-
* const listenerId = store.
|
|
2906
|
-
* '
|
|
2907
|
-
* 'fido',
|
|
2908
|
-
* (store, tableId, rowId) =>
|
|
2909
|
-
* store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
|
|
4318
|
+
* const store = createStore().setValues({open: true});
|
|
4319
|
+
* const listenerId = store.addValueIdsListener(
|
|
4320
|
+
* (store) => store.setValue('updated', true),
|
|
2910
4321
|
* true, // mutator
|
|
2911
4322
|
* );
|
|
2912
4323
|
*
|
|
2913
|
-
* store.
|
|
2914
|
-
* console.log(store.
|
|
2915
|
-
* // -> {
|
|
4324
|
+
* store.setValue('employees', 3);
|
|
4325
|
+
* console.log(store.getValues());
|
|
4326
|
+
* // -> {open: true, employees: 3, updated: true}
|
|
2916
4327
|
*
|
|
2917
4328
|
* store.delListener(listenerId);
|
|
2918
4329
|
* ```
|
|
2919
4330
|
* @category Listener
|
|
4331
|
+
* @since v3.0.0
|
|
2920
4332
|
*/
|
|
2921
|
-
|
|
2922
|
-
tableId: IdOrNull,
|
|
2923
|
-
rowId: IdOrNull,
|
|
2924
|
-
listener: CellIdsListener,
|
|
2925
|
-
mutator?: boolean,
|
|
2926
|
-
): Id;
|
|
4333
|
+
addValueIdsListener(listener: ValueIdsListener, mutator?: boolean): Id;
|
|
2927
4334
|
|
|
2928
4335
|
/**
|
|
2929
|
-
* The
|
|
2930
|
-
* that will be called whenever data in a
|
|
2931
|
-
*
|
|
2932
|
-
* The provided listener is a CellListener function, and will be called with a
|
|
2933
|
-
* reference to the Store, the Id of the Table that changed, the Id of the Row
|
|
2934
|
-
* that changed, the Id of the Cell that changed, the new Cell value, the old
|
|
2935
|
-
* Cell value, and a GetCellChange function in case you need to inspect any
|
|
2936
|
-
* changes that occurred.
|
|
4336
|
+
* The addValueListener method registers a listener function with the Store
|
|
4337
|
+
* that will be called whenever data in a Value changes.
|
|
2937
4338
|
*
|
|
2938
|
-
*
|
|
2939
|
-
*
|
|
2940
|
-
*
|
|
4339
|
+
* The provided listener is a ValueListener function, and will be called with
|
|
4340
|
+
* a reference to the Store, the Id of the Value that changed, the new Value
|
|
4341
|
+
* value, the old Value, and a GetValueChange function in case you need to
|
|
4342
|
+
* inspect any changes that occurred.
|
|
2941
4343
|
*
|
|
2942
|
-
*
|
|
2943
|
-
*
|
|
2944
|
-
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
2945
|
-
* every other combination of wildcards.
|
|
4344
|
+
* You can either listen to a single Value (by specifying the Value Id) or
|
|
4345
|
+
* changes to any Value (by providing a `null` wildcard).
|
|
2946
4346
|
*
|
|
2947
4347
|
* Use the optional mutator parameter to indicate that there is code in the
|
|
2948
4348
|
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
@@ -2952,96 +4352,76 @@ export interface Store {
|
|
|
2952
4352
|
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
2953
4353
|
* though they will fire non-mutator listeners.
|
|
2954
4354
|
*
|
|
2955
|
-
* @param
|
|
2956
|
-
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
2957
|
-
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
4355
|
+
* @param valueId The Id of the Value to listen to, or `null` as a wildcard.
|
|
2958
4356
|
* @param listener The function that will be called whenever data in the
|
|
2959
|
-
* matching
|
|
4357
|
+
* matching Value changes.
|
|
2960
4358
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2961
4359
|
* Store data.
|
|
2962
4360
|
* @returns A unique Id for the listener that can later be used to call it
|
|
2963
4361
|
* explicitly, or to remove it.
|
|
2964
4362
|
* @example
|
|
2965
4363
|
* This example registers a listener that responds to any changes to a
|
|
2966
|
-
* specific
|
|
4364
|
+
* specific Value.
|
|
2967
4365
|
*
|
|
2968
4366
|
* ```js
|
|
2969
|
-
* const store = createStore().
|
|
2970
|
-
*
|
|
2971
|
-
*
|
|
2972
|
-
*
|
|
2973
|
-
*
|
|
2974
|
-
*
|
|
2975
|
-
*
|
|
2976
|
-
* (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
|
|
2977
|
-
* console.log('color cell in fido row in pets table changed');
|
|
2978
|
-
* console.log([oldCell, newCell]);
|
|
2979
|
-
* console.log(getCellChange('pets', 'fido', 'color'));
|
|
4367
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
4368
|
+
* const listenerId = store.addValueListener(
|
|
4369
|
+
* 'employees',
|
|
4370
|
+
* (store, valueId, newValue, oldValue, getValueChange) => {
|
|
4371
|
+
* console.log('employee value changed');
|
|
4372
|
+
* console.log([oldValue, newValue]);
|
|
4373
|
+
* console.log(getValueChange('employees'));
|
|
2980
4374
|
* },
|
|
2981
4375
|
* );
|
|
2982
4376
|
*
|
|
2983
|
-
* store.
|
|
2984
|
-
* // -> '
|
|
2985
|
-
* // -> [
|
|
2986
|
-
* // -> [true,
|
|
4377
|
+
* store.setValue('employees', 4);
|
|
4378
|
+
* // -> 'employee value changed'
|
|
4379
|
+
* // -> [3, 4]
|
|
4380
|
+
* // -> [true, 3, 4]
|
|
2987
4381
|
*
|
|
2988
4382
|
* store.delListener(listenerId);
|
|
2989
4383
|
* ```
|
|
2990
4384
|
* @example
|
|
2991
|
-
* This example registers a listener that responds to any changes to any
|
|
4385
|
+
* This example registers a listener that responds to any changes to any
|
|
4386
|
+
* Value.
|
|
2992
4387
|
*
|
|
2993
4388
|
* ```js
|
|
2994
|
-
* const store = createStore().
|
|
2995
|
-
*
|
|
4389
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
4390
|
+
* const listenerId = store.addValueListener(null, (store, valueId) => {
|
|
4391
|
+
* console.log(`${valueId} value changed`);
|
|
2996
4392
|
* });
|
|
2997
|
-
* const listenerId = store.addCellListener(
|
|
2998
|
-
* null,
|
|
2999
|
-
* null,
|
|
3000
|
-
* null,
|
|
3001
|
-
* (store, tableId, rowId, cellId) => {
|
|
3002
|
-
* console.log(
|
|
3003
|
-
* `${cellId} cell in ${rowId} row in ${tableId} table changed`,
|
|
3004
|
-
* );
|
|
3005
|
-
* },
|
|
3006
|
-
* );
|
|
3007
4393
|
*
|
|
3008
|
-
* store.
|
|
3009
|
-
* // -> '
|
|
3010
|
-
* store.
|
|
3011
|
-
* // -> '
|
|
4394
|
+
* store.setValue('employees', 4);
|
|
4395
|
+
* // -> 'employees value changed'
|
|
4396
|
+
* store.setValue('open', false);
|
|
4397
|
+
* // -> 'open value changed'
|
|
3012
4398
|
*
|
|
3013
4399
|
* store.delListener(listenerId);
|
|
3014
4400
|
* ```
|
|
3015
4401
|
* @example
|
|
3016
4402
|
* This example registers a listener that responds to any changes to a
|
|
3017
|
-
* specific
|
|
4403
|
+
* specific Value, and which also mutates the Store itself.
|
|
3018
4404
|
*
|
|
3019
4405
|
* ```js
|
|
3020
|
-
* const store = createStore().
|
|
3021
|
-
*
|
|
3022
|
-
*
|
|
3023
|
-
*
|
|
3024
|
-
* 'pets',
|
|
3025
|
-
* 'fido',
|
|
3026
|
-
* 'color',
|
|
3027
|
-
* (store, tableId, rowId, cellId) =>
|
|
3028
|
-
* store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
|
|
4406
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
4407
|
+
* const listenerId = store.addValueListener(
|
|
4408
|
+
* 'employees',
|
|
4409
|
+
* (store, valueId) => store.setValue('updated', true),
|
|
3029
4410
|
* true,
|
|
3030
4411
|
* );
|
|
3031
4412
|
*
|
|
3032
|
-
* store.
|
|
3033
|
-
* console.log(store.
|
|
3034
|
-
* // -> {
|
|
4413
|
+
* store.delValue('employees');
|
|
4414
|
+
* console.log(store.getValues());
|
|
4415
|
+
* // -> {open: true, updated: true}
|
|
3035
4416
|
*
|
|
3036
4417
|
* store.delListener(listenerId);
|
|
3037
4418
|
* ```
|
|
3038
4419
|
* @category Listener
|
|
4420
|
+
* @since v3.0.0
|
|
3039
4421
|
*/
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
cellId: IdOrNull,
|
|
3044
|
-
listener: CellListener,
|
|
4422
|
+
addValueListener(
|
|
4423
|
+
valueId: IdOrNull,
|
|
4424
|
+
listener: ValueListener,
|
|
3045
4425
|
mutator?: boolean,
|
|
3046
4426
|
): Id;
|
|
3047
4427
|
|
|
@@ -3052,7 +4432,7 @@ export interface Store {
|
|
|
3052
4432
|
*
|
|
3053
4433
|
* The provided listener is an InvalidCellListener function, and will be
|
|
3054
4434
|
* called with a reference to the Store, the Id of the Table, the Id of the
|
|
3055
|
-
* Row, and the Id of Cell that
|
|
4435
|
+
* Row, and the Id of Cell that was being attempted to be changed. It is also
|
|
3056
4436
|
* given the invalid value of the Cell, which could have been of absolutely
|
|
3057
4437
|
* any type. Since there could have been multiple failed attempts to set the
|
|
3058
4438
|
* Cell within a single transaction, this is an array containing each attempt,
|
|
@@ -3076,19 +4456,20 @@ export interface Store {
|
|
|
3076
4456
|
* though they will fire non-mutator listeners.
|
|
3077
4457
|
*
|
|
3078
4458
|
* Special note should be made for how the listener will be called when a
|
|
3079
|
-
*
|
|
4459
|
+
* TablesSchema is present. The listener will be called:
|
|
3080
4460
|
*
|
|
3081
|
-
* - if a Table is being updated that is not specified in the
|
|
3082
|
-
* - if a Cell is of the wrong type specified in the
|
|
3083
|
-
* - if a Cell is omitted and is not defaulted in the
|
|
3084
|
-
* - if an empty Row is provided and there are no Cell defaults in the
|
|
4461
|
+
* - if a Table is being updated that is not specified in the TablesSchema
|
|
4462
|
+
* - if a Cell is of the wrong type specified in the TablesSchema
|
|
4463
|
+
* - if a Cell is omitted and is not defaulted in the TablesSchema
|
|
4464
|
+
* - if an empty Row is provided and there are no Cell defaults in the
|
|
4465
|
+
* TablesSchema
|
|
3085
4466
|
*
|
|
3086
|
-
* The listener will not be called if Cell that is defaulted in the
|
|
3087
|
-
* not provided, as long as all of the Cells that are _not_
|
|
3088
|
-
* provided.
|
|
4467
|
+
* The listener will not be called if a Cell that is defaulted in the
|
|
4468
|
+
* TablesSchema is not provided, as long as all of the Cells that are _not_
|
|
4469
|
+
* defaulted _are_ provided.
|
|
3089
4470
|
*
|
|
3090
4471
|
* To help understand all of these schema-based conditions, please see the
|
|
3091
|
-
*
|
|
4472
|
+
* TablesSchema example below.
|
|
3092
4473
|
*
|
|
3093
4474
|
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
3094
4475
|
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
@@ -3125,9 +4506,9 @@ export interface Store {
|
|
|
3125
4506
|
* ```
|
|
3126
4507
|
* @example
|
|
3127
4508
|
* This example registers a listener that responds to any invalid changes to
|
|
3128
|
-
* any Cell - in a Store _without_ a
|
|
3129
|
-
* cases where
|
|
3130
|
-
* objects are provided.
|
|
4509
|
+
* any Cell - in a Store _without_ a TablesSchema. Note also how it then
|
|
4510
|
+
* responds to cases where empty or invalid Row objects, or Table objects,
|
|
4511
|
+
* or Tables objects are provided.
|
|
3131
4512
|
*
|
|
3132
4513
|
* ```js
|
|
3133
4514
|
* const store = createStore().setTables({
|
|
@@ -3174,12 +4555,12 @@ export interface Store {
|
|
|
3174
4555
|
* ```
|
|
3175
4556
|
* @example
|
|
3176
4557
|
* This example registers a listener that responds to any invalid changes to
|
|
3177
|
-
* any Cell - in a Store _with_ a
|
|
3178
|
-
* missing parameters are provided for optional, and defaulted Cell
|
|
3179
|
-
* a Row.
|
|
4558
|
+
* any Cell - in a Store _with_ a TablesSchema. Note how it responds to cases
|
|
4559
|
+
* where missing parameters are provided for optional, and defaulted Cell
|
|
4560
|
+
* values in a Row.
|
|
3180
4561
|
*
|
|
3181
4562
|
* ```js
|
|
3182
|
-
* const store = createStore().
|
|
4563
|
+
* const store = createStore().setTablesSchema({
|
|
3183
4564
|
* pets: {
|
|
3184
4565
|
* species: {type: 'string'},
|
|
3185
4566
|
* color: {type: 'string', default: 'unknown'},
|
|
@@ -3220,7 +4601,7 @@ export interface Store {
|
|
|
3220
4601
|
* // -> {species: 'dog', color: 'unknown'}
|
|
3221
4602
|
* // The listener is not called, because color is defaulted
|
|
3222
4603
|
*
|
|
3223
|
-
* store.delTables().
|
|
4604
|
+
* store.delTables().setTablesSchema({
|
|
3224
4605
|
* pets: {
|
|
3225
4606
|
* species: {type: 'string'},
|
|
3226
4607
|
* color: {type: 'string'},
|
|
@@ -3275,6 +4656,182 @@ export interface Store {
|
|
|
3275
4656
|
mutator?: boolean,
|
|
3276
4657
|
): Id;
|
|
3277
4658
|
|
|
4659
|
+
/**
|
|
4660
|
+
* The addInvalidValueListener method registers a listener function with the
|
|
4661
|
+
* Store that will be called whenever invalid data was attempted to be written
|
|
4662
|
+
* to a Value.
|
|
4663
|
+
*
|
|
4664
|
+
* The provided listener is an InvalidValueListener function, and will be
|
|
4665
|
+
* called with a reference to the Store and the Id of Value that was being
|
|
4666
|
+
* attempted to be changed. It is also given the invalid value of the Value,
|
|
4667
|
+
* which could have been of absolutely any type. Since there could have been
|
|
4668
|
+
* multiple failed attempts to set the Value within a single transaction, this
|
|
4669
|
+
* is an array containing each attempt, chronologically.
|
|
4670
|
+
*
|
|
4671
|
+
* You can either listen to a single Value (by specifying the Value Id as the
|
|
4672
|
+
* method's first parameter) or invalid attempts to change any Value (by
|
|
4673
|
+
* providing a `null` wildcard).
|
|
4674
|
+
*
|
|
4675
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4676
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4677
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4678
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4679
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4680
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4681
|
+
* though they will fire non-mutator listeners.
|
|
4682
|
+
*
|
|
4683
|
+
* Special note should be made for how the listener will be called when a
|
|
4684
|
+
* ValuesSchema is present. The listener will be called:
|
|
4685
|
+
*
|
|
4686
|
+
* - if a Value is being updated that is not specified in the ValuesSchema
|
|
4687
|
+
* - if a Value is of the wrong type specified in the ValuesSchema
|
|
4688
|
+
* - if a Value is omitted when using setValues that is not defaulted in the
|
|
4689
|
+
* ValuesSchema
|
|
4690
|
+
*
|
|
4691
|
+
* The listener will not be called if a Value that is defaulted in the
|
|
4692
|
+
* ValuesSchema is not provided, as long as all of the Values that are _not_
|
|
4693
|
+
* defaulted _are_ provided.
|
|
4694
|
+
*
|
|
4695
|
+
* To help understand all of these schema-based conditions, please see the
|
|
4696
|
+
* ValuesSchema example below.
|
|
4697
|
+
*
|
|
4698
|
+
* @param valueId The Id of the Value to listen to, or `null` as a wildcard.
|
|
4699
|
+
* @param listener The function that will be called whenever an attempt to
|
|
4700
|
+
* write invalid data to the matching Value was made.
|
|
4701
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4702
|
+
* Store data.
|
|
4703
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4704
|
+
* explicitly, or to remove it.
|
|
4705
|
+
* @example
|
|
4706
|
+
* This example registers a listener that responds to any invalid changes to a
|
|
4707
|
+
* specific Value.
|
|
4708
|
+
*
|
|
4709
|
+
* ```js
|
|
4710
|
+
* const store = createStore().setValues({open: true});
|
|
4711
|
+
* const listenerId = store.addInvalidValueListener(
|
|
4712
|
+
* 'open',
|
|
4713
|
+
* (store, valueId, invalidValues) => {
|
|
4714
|
+
* console.log('Invalid open value');
|
|
4715
|
+
* console.log(invalidValues);
|
|
4716
|
+
* },
|
|
4717
|
+
* );
|
|
4718
|
+
*
|
|
4719
|
+
* store.setValue('open', {yes: true});
|
|
4720
|
+
* // -> 'Invalid open value'
|
|
4721
|
+
* // -> [{yes: true}]
|
|
4722
|
+
*
|
|
4723
|
+
* store.delListener(listenerId);
|
|
4724
|
+
* ```
|
|
4725
|
+
* @example
|
|
4726
|
+
* This example registers a listener that responds to any invalid changes to
|
|
4727
|
+
* any Value - in a Store _without_ a ValuesSchema. Note also how it then
|
|
4728
|
+
* responds to cases where an empty Values object is provided.
|
|
4729
|
+
*
|
|
4730
|
+
* ```js
|
|
4731
|
+
* const store = createStore().setValues({open: true});
|
|
4732
|
+
* const listenerId = store.addInvalidValueListener(
|
|
4733
|
+
* null,
|
|
4734
|
+
* (store, valueId) => {
|
|
4735
|
+
* console.log(`Invalid ${valueId} value`);
|
|
4736
|
+
* },
|
|
4737
|
+
* );
|
|
4738
|
+
*
|
|
4739
|
+
* store.setValue('open', {yes: true});
|
|
4740
|
+
* // -> 'Invalid open value'
|
|
4741
|
+
* store.setValue('employees', ['alice', 'bob']);
|
|
4742
|
+
* // -> 'Invalid employees value'
|
|
4743
|
+
*
|
|
4744
|
+
* store.setValues('pets', 'felix', {});
|
|
4745
|
+
* // -> 'Invalid undefined value'
|
|
4746
|
+
*
|
|
4747
|
+
* store.delListener(listenerId);
|
|
4748
|
+
* ```
|
|
4749
|
+
* @example
|
|
4750
|
+
* This example registers a listener that responds to any invalid changes to
|
|
4751
|
+
* any Value - in a Store _with_ a ValuesSchema. Note how it responds to cases
|
|
4752
|
+
* where missing parameters are provided for optional, and defaulted Values.
|
|
4753
|
+
*
|
|
4754
|
+
* ```js
|
|
4755
|
+
* const store = createStore().setValuesSchema({
|
|
4756
|
+
* open: {type: 'boolean', default: false},
|
|
4757
|
+
* employees: {type: 'number'},
|
|
4758
|
+
* });
|
|
4759
|
+
*
|
|
4760
|
+
* console.log(store.getValues());
|
|
4761
|
+
* // -> {open: false}
|
|
4762
|
+
*
|
|
4763
|
+
* const listenerId = store.addInvalidValueListener(
|
|
4764
|
+
* null,
|
|
4765
|
+
* (store, valueId) => {
|
|
4766
|
+
* console.log(`Invalid ${valueId} value`);
|
|
4767
|
+
* },
|
|
4768
|
+
* );
|
|
4769
|
+
*
|
|
4770
|
+
* store.setValue('website', true);
|
|
4771
|
+
* // -> 'Invalid website value'
|
|
4772
|
+
* // The listener is called, because the website Value is not in the schema
|
|
4773
|
+
*
|
|
4774
|
+
* store.setValue('open', 'yes');
|
|
4775
|
+
* // -> 'Invalid open value'
|
|
4776
|
+
* // The listener is called, because 'open' is invalid...
|
|
4777
|
+
* console.log(store.getValues());
|
|
4778
|
+
* // -> {open: false}
|
|
4779
|
+
* // ...even though it is still present with the default value
|
|
4780
|
+
*
|
|
4781
|
+
* store.setValues({open: true});
|
|
4782
|
+
* // -> 'Invalid employees value'
|
|
4783
|
+
* // The listener is called because employees is missing and not defaulted...
|
|
4784
|
+
* console.log(store.getValues());
|
|
4785
|
+
* // -> {open: true}
|
|
4786
|
+
* // ...even though the Values were set
|
|
4787
|
+
*
|
|
4788
|
+
* store.setValues({employees: 3});
|
|
4789
|
+
* console.log(store.getValues());
|
|
4790
|
+
* // -> {open: false, employees: 3}
|
|
4791
|
+
* // The listener is not called, because 'open' is defaulted
|
|
4792
|
+
*
|
|
4793
|
+
* store.setValuesSchema({
|
|
4794
|
+
* open: {type: 'boolean'},
|
|
4795
|
+
* employees: {type: 'number'},
|
|
4796
|
+
* });
|
|
4797
|
+
*
|
|
4798
|
+
* store.setValues({});
|
|
4799
|
+
* // -> 'Invalid open value'
|
|
4800
|
+
* // -> 'Invalid employees value'
|
|
4801
|
+
* // -> 'Invalid undefined value'
|
|
4802
|
+
* // The listener is called multiple times, because neither Value is
|
|
4803
|
+
* // defaulted and the Values as a whole were empty
|
|
4804
|
+
*
|
|
4805
|
+
* store.delListener(listenerId);
|
|
4806
|
+
* ```
|
|
4807
|
+
* @example
|
|
4808
|
+
* This example registers a listener that responds to any changes to a
|
|
4809
|
+
* specific Value, and which also mutates the Store itself.
|
|
4810
|
+
*
|
|
4811
|
+
* ```js
|
|
4812
|
+
* const store = createStore().setValues({open: true});
|
|
4813
|
+
* const listenerId = store.addInvalidValueListener(
|
|
4814
|
+
* 'open',
|
|
4815
|
+
* (store, valueId, invalidValues) =>
|
|
4816
|
+
* store.setValue('invalid_updates', JSON.stringify(invalidValues[0])),
|
|
4817
|
+
* true,
|
|
4818
|
+
* );
|
|
4819
|
+
*
|
|
4820
|
+
* store.setValue('open', {yes: true});
|
|
4821
|
+
* console.log(store.getValue('invalid_updates'));
|
|
4822
|
+
* // -> '{"yes":true}'
|
|
4823
|
+
*
|
|
4824
|
+
* store.delListener(listenerId);
|
|
4825
|
+
* ```
|
|
4826
|
+
* @category Listener
|
|
4827
|
+
* @since v3.0.0
|
|
4828
|
+
*/
|
|
4829
|
+
addInvalidValueListener(
|
|
4830
|
+
valueId: IdOrNull,
|
|
4831
|
+
listener: InvalidValueListener,
|
|
4832
|
+
mutator?: boolean,
|
|
4833
|
+
): Id;
|
|
4834
|
+
|
|
3278
4835
|
/**
|
|
3279
4836
|
* The addWillFinishTransactionListener method registers a listener function
|
|
3280
4837
|
* with the Store that will be called just before other non-mutating listeners
|
|
@@ -3285,59 +4842,82 @@ export interface Store {
|
|
|
3285
4842
|
* together.
|
|
3286
4843
|
*
|
|
3287
4844
|
* The provided TransactionListener will receive a reference to the Store and
|
|
3288
|
-
*
|
|
3289
|
-
* transaction. The
|
|
4845
|
+
* two booleans to indicate whether Cell or Value data has been touched during
|
|
4846
|
+
* the transaction. The two flags are intended as a hint about whether
|
|
3290
4847
|
* non-mutating listeners might be being called at the end of the transaction.
|
|
3291
4848
|
*
|
|
3292
|
-
* Here, 'touched' means that Cell
|
|
3293
|
-
* and then changed back to its original value during the transaction.
|
|
3294
|
-
* exception is a transaction that has been rolled back, for which the
|
|
3295
|
-
* of `cellsTouched` in the listener will be `false`
|
|
3296
|
-
* been reverted.
|
|
4849
|
+
* Here, 'touched' means that Cell or Value data has either been changed, or
|
|
4850
|
+
* changed and then changed back to its original value during the transaction.
|
|
4851
|
+
* The exception is a transaction that has been rolled back, for which the
|
|
4852
|
+
* value of `cellsTouched` and `valuesTouched` in the listener will be `false`
|
|
4853
|
+
* because all changes have been reverted.
|
|
3297
4854
|
*
|
|
3298
4855
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
3299
4856
|
* @example
|
|
3300
4857
|
* This example registers a listener that is called at the end of the
|
|
3301
4858
|
* transaction, just before its listeners will be called. The transactions
|
|
3302
4859
|
* shown here variously change, touch, and rollback cells, demonstrating how
|
|
3303
|
-
* the `cellsTouched`
|
|
4860
|
+
* the `cellsTouched` and `valuesTouched` parameters in the listener work.
|
|
3304
4861
|
*
|
|
3305
4862
|
* ```js
|
|
3306
|
-
* const store = createStore()
|
|
3307
|
-
*
|
|
3308
|
-
* }
|
|
4863
|
+
* const store = createStore()
|
|
4864
|
+
* .setTables({
|
|
4865
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4866
|
+
* })
|
|
4867
|
+
* .setValues({open: true, employees: 3});
|
|
3309
4868
|
* const listenerId = store.addWillFinishTransactionListener(
|
|
3310
|
-
* (store, cellsTouched) =>
|
|
4869
|
+
* (store, cellsTouched, valuesTouched) => {
|
|
4870
|
+
* console.log(`Cells/Values touched: ${cellsTouched}/${valuesTouched}`);
|
|
4871
|
+
* },
|
|
3311
4872
|
* );
|
|
3312
4873
|
* const listenerId2 = store.addTablesListener(() =>
|
|
3313
4874
|
* console.log('Tables changed'),
|
|
3314
4875
|
* );
|
|
4876
|
+
* const listenerId3 = store.addValuesListener(() =>
|
|
4877
|
+
* console.log('Values changed'),
|
|
4878
|
+
* );
|
|
3315
4879
|
*
|
|
3316
|
-
* store.transaction(() =>
|
|
3317
|
-
*
|
|
4880
|
+
* store.transaction(() =>
|
|
4881
|
+
* store.setCell('pets', 'fido', 'color', 'brown').setValue('employees', 3),
|
|
4882
|
+
* );
|
|
4883
|
+
* // -> 'Cells/Values touched: false/false'
|
|
3318
4884
|
*
|
|
3319
4885
|
* store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
|
|
3320
|
-
* // -> 'Cells touched: true'
|
|
4886
|
+
* // -> 'Cells/Values touched: true/false'
|
|
3321
4887
|
* // -> 'Tables changed'
|
|
3322
4888
|
*
|
|
4889
|
+
* store.transaction(() => store.setValue('employees', 4));
|
|
4890
|
+
* // -> 'Cells/Values touched: false/true'
|
|
4891
|
+
* // -> 'Values changed'
|
|
4892
|
+
*
|
|
3323
4893
|
* store.transaction(() => {
|
|
3324
|
-
* store
|
|
3325
|
-
*
|
|
4894
|
+
* store
|
|
4895
|
+
* .setRow('pets', 'felix', {species: 'cat'})
|
|
4896
|
+
* .delRow('pets', 'felix')
|
|
4897
|
+
* .setValue('city', 'London')
|
|
4898
|
+
* .delValue('city');
|
|
3326
4899
|
* });
|
|
3327
|
-
* // -> 'Cells touched: true'
|
|
4900
|
+
* // -> 'Cells/Values touched: true/true'
|
|
4901
|
+
* // But no Tables or Values listeners fired since there are no net changes.
|
|
3328
4902
|
*
|
|
3329
4903
|
* store.transaction(
|
|
3330
|
-
* () =>
|
|
4904
|
+
* () =>
|
|
4905
|
+
* store
|
|
4906
|
+
* .setRow('pets', 'felix', {species: 'cat'})
|
|
4907
|
+
* .setValue('city', 'London'),
|
|
3331
4908
|
* () => true,
|
|
3332
4909
|
* );
|
|
3333
|
-
* // -> 'Cells touched: false'
|
|
4910
|
+
* // -> 'Cells/Values touched: false/false'
|
|
3334
4911
|
* // Transaction was rolled back.
|
|
3335
4912
|
*
|
|
3336
4913
|
* store.callListener(listenerId);
|
|
3337
|
-
* // -> 'Cells touched: undefined'
|
|
4914
|
+
* // -> 'Cells/Values touched: undefined/undefined'
|
|
3338
4915
|
* // It is meaningless to call this listener directly.
|
|
3339
4916
|
*
|
|
3340
|
-
* store
|
|
4917
|
+
* store
|
|
4918
|
+
* .delListener(listenerId)
|
|
4919
|
+
* .delListener(listenerId2)
|
|
4920
|
+
* .delListener(listenerId3);
|
|
3341
4921
|
* ```
|
|
3342
4922
|
* @category Listener
|
|
3343
4923
|
* @since v1.3.0
|
|
@@ -3354,60 +4934,83 @@ export interface Store {
|
|
|
3354
4934
|
* together.
|
|
3355
4935
|
*
|
|
3356
4936
|
* The provided TransactionListener will receive a reference to the Store and
|
|
3357
|
-
*
|
|
3358
|
-
* transaction. The
|
|
4937
|
+
* two booleans to indicate whether Cell or Value data has been touched during
|
|
4938
|
+
* the transaction. The two flags is intended as a hint about whether
|
|
3359
4939
|
* non-mutating listeners might have been called at the end of the
|
|
3360
4940
|
* transaction.
|
|
3361
4941
|
*
|
|
3362
|
-
* Here, 'touched' means that Cell
|
|
3363
|
-
* and then changed back to its original value during the transaction.
|
|
3364
|
-
* exception is a transaction that has been rolled back, for which the
|
|
3365
|
-
* of `cellsTouched` in the listener will be `false`
|
|
3366
|
-
* been reverted.
|
|
4942
|
+
* Here, 'touched' means that Cell or Value data has either been changed, or
|
|
4943
|
+
* changed and then changed back to its original value during the transaction.
|
|
4944
|
+
* The exception is a transaction that has been rolled back, for which the
|
|
4945
|
+
* value of `cellsTouched` and `valuesTouched` in the listener will be `false`
|
|
4946
|
+
* because all changes have been reverted.
|
|
3367
4947
|
*
|
|
3368
4948
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
3369
4949
|
* @example
|
|
3370
4950
|
* This example registers a listener that is called at the end of the
|
|
3371
4951
|
* transaction, just after its listeners have been called. The transactions
|
|
3372
4952
|
* shown here variously change, touch, and rollback cells, demonstrating how
|
|
3373
|
-
* the `cellsTouched`
|
|
4953
|
+
* the `cellsTouched` and `valuesTouched` parameters in the listener work.
|
|
3374
4954
|
*
|
|
3375
4955
|
* ```js
|
|
3376
|
-
* const store = createStore()
|
|
3377
|
-
*
|
|
3378
|
-
* }
|
|
4956
|
+
* const store = createStore()
|
|
4957
|
+
* .setTables({
|
|
4958
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4959
|
+
* })
|
|
4960
|
+
* .setValues({open: true, employees: 3});
|
|
3379
4961
|
* const listenerId = store.addDidFinishTransactionListener(
|
|
3380
|
-
* (store, cellsTouched) =>
|
|
4962
|
+
* (store, cellsTouched, valuesTouched) => {
|
|
4963
|
+
* console.log(`Cells/Values touched: ${cellsTouched}/${valuesTouched}`);
|
|
4964
|
+
* },
|
|
3381
4965
|
* );
|
|
3382
4966
|
* const listenerId2 = store.addTablesListener(() =>
|
|
3383
4967
|
* console.log('Tables changed'),
|
|
3384
4968
|
* );
|
|
4969
|
+
* const listenerId3 = store.addValuesListener(() =>
|
|
4970
|
+
* console.log('Values changed'),
|
|
4971
|
+
* );
|
|
3385
4972
|
*
|
|
3386
|
-
* store.transaction(() =>
|
|
3387
|
-
*
|
|
4973
|
+
* store.transaction(() =>
|
|
4974
|
+
* store.setCell('pets', 'fido', 'color', 'brown').setValue('employees', 3),
|
|
4975
|
+
* );
|
|
4976
|
+
* // -> 'Cells/Values touched: false/false'
|
|
3388
4977
|
*
|
|
3389
4978
|
* store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
|
|
3390
4979
|
* // -> 'Tables changed'
|
|
3391
|
-
* // -> 'Cells touched: true'
|
|
4980
|
+
* // -> 'Cells/Values touched: true/false'
|
|
4981
|
+
*
|
|
4982
|
+
* store.transaction(() => store.setValue('employees', 4));
|
|
4983
|
+
* // -> 'Values changed'
|
|
4984
|
+
* // -> 'Cells/Values touched: false/true'
|
|
3392
4985
|
*
|
|
3393
4986
|
* store.transaction(() => {
|
|
3394
|
-
* store
|
|
3395
|
-
*
|
|
4987
|
+
* store
|
|
4988
|
+
* .setRow('pets', 'felix', {species: 'cat'})
|
|
4989
|
+
* .delRow('pets', 'felix')
|
|
4990
|
+
* .setValue('city', 'London')
|
|
4991
|
+
* .delValue('city');
|
|
3396
4992
|
* });
|
|
3397
|
-
* // -> 'Cells touched: true'
|
|
4993
|
+
* // -> 'Cells/Values touched: true/true'
|
|
4994
|
+
* // But no Tables or Values listeners fired since there are no net changes.
|
|
3398
4995
|
*
|
|
3399
4996
|
* store.transaction(
|
|
3400
|
-
* () =>
|
|
4997
|
+
* () =>
|
|
4998
|
+
* store
|
|
4999
|
+
* .setRow('pets', 'felix', {species: 'cat'})
|
|
5000
|
+
* .setValue('city', 'London'),
|
|
3401
5001
|
* () => true,
|
|
3402
5002
|
* );
|
|
3403
|
-
* // -> 'Cells touched: false'
|
|
5003
|
+
* // -> 'Cells/Values touched: false/false'
|
|
3404
5004
|
* // Transaction was rolled back.
|
|
3405
5005
|
*
|
|
3406
5006
|
* store.callListener(listenerId);
|
|
3407
|
-
* // -> 'Cells touched: undefined'
|
|
5007
|
+
* // -> 'Cells/Values touched: undefined/undefined'
|
|
3408
5008
|
* // It is meaningless to call this listener directly.
|
|
3409
5009
|
*
|
|
3410
|
-
* store
|
|
5010
|
+
* store
|
|
5011
|
+
* .delListener(listenerId)
|
|
5012
|
+
* .delListener(listenerId2)
|
|
5013
|
+
* .delListener(listenerId3);
|
|
3411
5014
|
* ```
|
|
3412
5015
|
* @category Listener
|
|
3413
5016
|
* @since v1.3.0
|
|
@@ -3458,6 +5061,75 @@ export interface Store {
|
|
|
3458
5061
|
*
|
|
3459
5062
|
* store.delListener(listenerId);
|
|
3460
5063
|
* ```
|
|
5064
|
+
* @example
|
|
5065
|
+
* This example registers a listener to Row Id changes. It is explicitly
|
|
5066
|
+
* called and fires for two Tables in the Store.
|
|
5067
|
+
*
|
|
5068
|
+
* ```js
|
|
5069
|
+
* const store = createStore().setTables({
|
|
5070
|
+
* pets: {fido: {species: 'dog'}},
|
|
5071
|
+
* species: {dog: {price: 5}},
|
|
5072
|
+
* });
|
|
5073
|
+
*
|
|
5074
|
+
* const listenerId = store.addRowIdsListener(null, (store, tableId) => {
|
|
5075
|
+
* console.log(`Row Ids listener called for ${tableId} table`);
|
|
5076
|
+
* });
|
|
5077
|
+
*
|
|
5078
|
+
* store.callListener(listenerId);
|
|
5079
|
+
* // -> 'Row Ids listener called for pets table'
|
|
5080
|
+
* // -> 'Row Ids listener called for species table'
|
|
5081
|
+
*
|
|
5082
|
+
* store.delListener(listenerId);
|
|
5083
|
+
* ```
|
|
5084
|
+
* @example
|
|
5085
|
+
* This example registers a listener Value changes. It is explicitly called
|
|
5086
|
+
* and fires for two Values in the Store.
|
|
5087
|
+
*
|
|
5088
|
+
* ```js
|
|
5089
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
5090
|
+
*
|
|
5091
|
+
* const listenerId = store.addValueListener(
|
|
5092
|
+
* null,
|
|
5093
|
+
* (store, valueId, value) => {
|
|
5094
|
+
* console.log(`Value listener called for ${valueId} value, ${value}`);
|
|
5095
|
+
* },
|
|
5096
|
+
* );
|
|
5097
|
+
*
|
|
5098
|
+
* store.callListener(listenerId);
|
|
5099
|
+
* // -> 'Value listener called for open value, true'
|
|
5100
|
+
* // -> 'Value listener called for employees value, 3'
|
|
5101
|
+
*
|
|
5102
|
+
* store.delListener(listenerId);
|
|
5103
|
+
* ```
|
|
5104
|
+
* @example
|
|
5105
|
+
* This example registers listeners for the end of transactions, and for
|
|
5106
|
+
* invalid Cells. The are explicitly called, meaninglessly. The former
|
|
5107
|
+
* receives empty arguments. The latter is not called at all.
|
|
5108
|
+
*
|
|
5109
|
+
* ```js
|
|
5110
|
+
* const store = createStore();
|
|
5111
|
+
*
|
|
5112
|
+
* const listenerId = store.addWillFinishTransactionListener(
|
|
5113
|
+
* (store, cellsTouched, valuesTouched) => {
|
|
5114
|
+
* console.log(`Transaction finish: ${cellsTouched}/${valuesTouched}`);
|
|
5115
|
+
* },
|
|
5116
|
+
* );
|
|
5117
|
+
* store.callListener(listenerId);
|
|
5118
|
+
* // -> 'Transaction finish: undefined/undefined'
|
|
5119
|
+
* store.delListener(listenerId);
|
|
5120
|
+
*
|
|
5121
|
+
* const listenerId2 = store.addInvalidCellListener(
|
|
5122
|
+
* null,
|
|
5123
|
+
* null,
|
|
5124
|
+
* null,
|
|
5125
|
+
* (store, tableId, rowId, cellId) => {
|
|
5126
|
+
* console.log('Invalid cell', tableId, rowId, cellId);
|
|
5127
|
+
* },
|
|
5128
|
+
* );
|
|
5129
|
+
* store.callListener(listenerId2);
|
|
5130
|
+
* // -> undefined
|
|
5131
|
+
* store.delListener(listenerId2);
|
|
5132
|
+
* ```
|
|
3461
5133
|
* @category Listener
|
|
3462
5134
|
*/
|
|
3463
5135
|
callListener(listenerId: Id): Store;
|
|
@@ -3552,12 +5224,12 @@ export interface Store {
|
|
|
3552
5224
|
* // -> {pets: {fido: {species: 'dog'}}}
|
|
3553
5225
|
* ```
|
|
3554
5226
|
* @example
|
|
3555
|
-
* This example creates a Store with some initial data and a
|
|
5227
|
+
* This example creates a Store with some initial data and a TablesSchema:
|
|
3556
5228
|
*
|
|
3557
5229
|
* ```js
|
|
3558
5230
|
* const store = createStore()
|
|
3559
5231
|
* .setTables({pets: {fido: {species: 'dog'}}})
|
|
3560
|
-
* .
|
|
5232
|
+
* .setTablesSchema({
|
|
3561
5233
|
* pets: {
|
|
3562
5234
|
* species: {type: 'string'},
|
|
3563
5235
|
* sold: {type: 'boolean', default: false},
|