tinybase 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/package.json +9 -2
  2. package/lib/checkpoints.d.ts +0 -879
  3. package/lib/checkpoints.js +0 -1
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/common.d.ts +0 -115
  6. package/lib/common.js +0 -1
  7. package/lib/common.js.gz +0 -0
  8. package/lib/debug/checkpoints.js +0 -326
  9. package/lib/debug/common.js +0 -3
  10. package/lib/debug/indexes.js +0 -398
  11. package/lib/debug/metrics.js +0 -391
  12. package/lib/debug/persisters.js +0 -191
  13. package/lib/debug/relationships.js +0 -418
  14. package/lib/debug/store.js +0 -725
  15. package/lib/indexes.d.ts +0 -778
  16. package/lib/indexes.js +0 -1
  17. package/lib/indexes.js.gz +0 -0
  18. package/lib/metrics.d.ts +0 -757
  19. package/lib/metrics.js +0 -1
  20. package/lib/metrics.js.gz +0 -0
  21. package/lib/persisters.d.ts +0 -711
  22. package/lib/persisters.js +0 -1
  23. package/lib/persisters.js.gz +0 -0
  24. package/lib/relationships.d.ts +0 -1116
  25. package/lib/relationships.js +0 -1
  26. package/lib/relationships.js.gz +0 -0
  27. package/lib/store.d.ts +0 -2506
  28. package/lib/store.js +0 -1
  29. package/lib/store.js.gz +0 -0
  30. package/lib/tinybase.d.ts +0 -13
  31. package/lib/tinybase.js +0 -1
  32. package/lib/tinybase.js.gz +0 -0
  33. package/lib/ui-react.d.ts +0 -7185
  34. package/lib/ui-react.js +0 -1
  35. package/lib/ui-react.js.gz +0 -0
  36. package/lib/umd/checkpoints.js +0 -1
  37. package/lib/umd/checkpoints.js.gz +0 -0
  38. package/lib/umd/common.js +0 -1
  39. package/lib/umd/common.js.gz +0 -0
  40. package/lib/umd/indexes.js +0 -1
  41. package/lib/umd/indexes.js.gz +0 -0
  42. package/lib/umd/metrics.js +0 -1
  43. package/lib/umd/metrics.js.gz +0 -0
  44. package/lib/umd/persisters.js +0 -1
  45. package/lib/umd/persisters.js.gz +0 -0
  46. package/lib/umd/relationships.js +0 -1
  47. package/lib/umd/relationships.js.gz +0 -0
  48. package/lib/umd/store.js +0 -1
  49. package/lib/umd/store.js.gz +0 -0
  50. package/lib/umd/tinybase.js +0 -1
  51. package/lib/umd/tinybase.js.gz +0 -0
  52. package/lib/umd/ui-react.js +0 -1
  53. package/lib/umd/ui-react.js.gz +0 -0
@@ -1,879 +0,0 @@
1
- /**
2
- * The checkpoints module of the TinyBase project provides the ability to
3
- * create and track checkpoints made to the data in Store objects.
4
- *
5
- * The main entry point to this module is the createCheckpoints function, which
6
- * returns a new Checkpoints object. From there, you can create new checkpoints,
7
- * go forwards or backwards to others, and register listeners for when the list
8
- * of checkpoints change.
9
- *
10
- * @packageDocumentation
11
- * @module checkpoints
12
- */
13
-
14
- import {Id, IdOrNull, Ids} from './common.d';
15
- import {Store} from './store.d';
16
-
17
- /**
18
- * The CheckpointIds type is a representation of the list of checkpoint Ids
19
- * stored in a Checkpoints object.
20
- *
21
- * There are three parts to a CheckpointsIds array:
22
- *
23
- * - The 'backward' checkpoint Ids that can be rolled backward to (in other
24
- * words, the checkpoints in the undo stack for this Store). They are in
25
- * chronological order with the oldest checkpoint at the start of the array.
26
- * - The current checkpoint Id of the Store's state, or `undefined` if the
27
- * current state has not been checkpointed.
28
- * - The 'forward' checkpoint Ids that can be rolled forward to (in other words,
29
- * the checkpoints in the redo stack for this Store). They are in
30
- * chronological order with the newest checkpoint at the end of the array.
31
- *
32
- * @category Identity
33
- */
34
- export type CheckpointIds = [Ids, Id | undefined, Ids];
35
-
36
- /**
37
- * The CheckpointIdsListener type describes a function that is used to listen to
38
- * changes to the checkpoint Ids in a Checkpoints object.
39
- *
40
- * A CheckpointIdsListener is provided when using the addCheckpointIdsListener
41
- * method. See that method for specific examples.
42
- *
43
- * When called, a CheckpointIdsListener is given a reference to the Checkpoints
44
- * object.
45
- *
46
- * @param checkpoints A reference to the Checkpoints object that changed.
47
- * @category Listener
48
- */
49
- export type CheckpointIdsListener = (checkpoints: Checkpoints) => void;
50
-
51
- /**
52
- * The CheckpointListener type describes a function that is used to listen to
53
- * changes to a checkpoint's label in a Checkpoints object.
54
- *
55
- * A CheckpointListener is provided when using the addCheckpointListener method.
56
- * See that method for specific examples.
57
- *
58
- * When called, a CheckpointListener is given a reference to the Checkpoints
59
- * object, and the Id of the checkpoint whose label changed.
60
- *
61
- * @param checkpoints A reference to the Checkpoints object that changed.
62
- * @param checkpointId The Id of the checkpoint that changed.
63
- * @category Listener
64
- */
65
- export type CheckpointListener = (
66
- checkpoints: Checkpoints,
67
- checkpointId: Id,
68
- ) => void;
69
-
70
- /**
71
- * The CheckpointsListenerStats type describes the number of listeners
72
- * registered with the Checkpoints object, and can be used for debugging
73
- * purposes.
74
- *
75
- * A CheckpointsListenerStats object is returned from the getListenerStats
76
- * method, and is only populated in a debug build.
77
- *
78
- * @category Development
79
- */
80
- export type CheckpointsListenerStats = {
81
- /**
82
- * The number of CheckpointIdsListeners registered with the Checkpoints
83
- * object.
84
- */
85
- checkpointIds?: number;
86
- /**
87
- * The number of CheckpointListeners registered with the Checkpoints object.
88
- */
89
- checkpoint?: number;
90
- };
91
-
92
- /**
93
- * A Checkpoints object lets you set checkpoints on a Store, and move forward
94
- * and backward through them to create undo and redo functionality.
95
- *
96
- * Create a Checkpoints object easily with the createCheckpoints function. From
97
- * there, you can set checkpoints (with the addCheckpoint method), query the
98
- * checkpoints available (with the getCheckpointIds method), move forward and
99
- * backward through them (with the goBackward method, goForward method, and goTo
100
- * method), and add listeners for when the list checkpoints changes (with the
101
- * addCheckpointIdsListener method).
102
- *
103
- * Every checkpoint can be given a label which can be used to describe the
104
- * actions that changed the Store before this checkpoint. This can be useful for
105
- * interfaces that let users 'Undo [last action]'.
106
- *
107
- * You
108
- *
109
- * @example
110
- * This example shows a simple lifecycle of a Checkpoints object: from creation,
111
- * to adding a checkpoint, getting the list of available checkpoints, and then
112
- * registering and removing a listener for them.
113
- *
114
- * ```js
115
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
116
- *
117
- * const checkpoints = createCheckpoints(store);
118
- * checkpoints.setSize(200);
119
- * console.log(checkpoints.getCheckpointIds());
120
- * // -> [[], '0', []]
121
- *
122
- * store.setCell('pets', 'fido', 'sold', true);
123
- * checkpoints.addCheckpoint('sale');
124
- * console.log(checkpoints.getCheckpointIds());
125
- * // -> [['0'], '1', []]
126
- *
127
- * checkpoints.goBackward();
128
- * console.log(store.getCell('pets', 'fido', 'sold'));
129
- * // -> false
130
- * console.log(checkpoints.getCheckpointIds());
131
- * // -> [[], '0', ['1']]
132
- *
133
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
134
- * console.log(checkpoints.getCheckpointIds());
135
- * });
136
- * store.setCell('pets', 'fido', 'species', 'dog');
137
- * // -> [['0'], undefined, []]
138
- * checkpoints.addCheckpoint();
139
- * // -> [['0'], '2', []]
140
- * // Previous redo of checkpoint '1' is now not possible.
141
- *
142
- * checkpoints.delListener(listenerId);
143
- * checkpoints.destroy();
144
- * ```
145
- * @see Relationships And Checkpoints guides
146
- * @see Todo App demos
147
- * @see TinyDraw demo
148
- * @category Checkpoints
149
- */
150
- export interface Checkpoints {
151
- /**
152
- * The setSize method lets you specify how many checkpoints the Checkpoints
153
- * object will store.
154
- *
155
- * If you set more checkpoints than this size, the oldest checkpoints will be
156
- * pruned to make room for more recent ones.
157
- *
158
- * The default size for a newly-created Checkpoints object is 100.
159
- *
160
- * @param size The number of checkpoints that this Checkpoints object should
161
- * hold.
162
- * @returns A reference to the Checkpoints object.
163
- * @example
164
- * This example creates a Store, adds a Checkpoints object, reduces the size
165
- * of the Checkpoints object dramatically and then creates more than that
166
- * number of checkpoints to demonstrate the oldest being pruned.
167
- *
168
- * ```js
169
- * const store = createStore().setTables({pets: {fido: {views: 0}}});
170
- *
171
- * const checkpoints = createCheckpoints(store);
172
- * checkpoints.setSize(2);
173
- * console.log(checkpoints.getCheckpointIds());
174
- * // -> [[], '0', []]
175
- *
176
- * store.setCell('pets', 'fido', 'views', 1);
177
- * checkpoints.addCheckpoint();
178
- * console.log(checkpoints.getCheckpointIds());
179
- * // -> [['0'], '1', []]
180
- *
181
- * store.setCell('pets', 'fido', 'views', 2);
182
- * checkpoints.addCheckpoint();
183
- * console.log(checkpoints.getCheckpointIds());
184
- * // -> [['0', '1'], '2', []]
185
- *
186
- * store.setCell('pets', 'fido', 'views', 3);
187
- * checkpoints.addCheckpoint();
188
- * console.log(checkpoints.getCheckpointIds());
189
- * // -> [['1', '2'], '3', []]
190
- * ```
191
- * @category Configuration
192
- */
193
- setSize(size: number): Checkpoints;
194
-
195
- /**
196
- * The addCheckpoint method records a checkpoint of the Store into the
197
- * Checkpoints object that can be reverted to in the future.
198
- *
199
- * If no changes have been made to the Store since the last time a checkpoint
200
- * was made, this method will have no effect.
201
- *
202
- * The optional `label` parameter can be used to describe the actions that
203
- * changed the Store before this checkpoint. This can be useful for interfaces
204
- * that let users 'Undo [last action]'.
205
- *
206
- * @param label An optional label to describe the actions leading up to this
207
- * checkpoint.
208
- * @returns The Id of the newly-created checkpoint.
209
- * @example
210
- * This example creates a Store, adds a Checkpoints object, and adds two
211
- * checkpoints, one with a label.
212
- *
213
- * ```js
214
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
215
- *
216
- * const checkpoints = createCheckpoints(store);
217
- * console.log(checkpoints.getCheckpointIds());
218
- * // -> [[], '0', []]
219
- *
220
- * store.setCell('pets', 'fido', 'species', 'dog');
221
- * const checkpointId1 = checkpoints.addCheckpoint();
222
- * console.log(checkpointId1);
223
- * // -> '1'
224
- *
225
- * console.log(checkpoints.getCheckpointIds());
226
- * // -> [['0'], '1', []]
227
- *
228
- * store.setCell('pets', 'fido', 'sold', true);
229
- * checkpoints.addCheckpoint('sale');
230
- * console.log(checkpoints.getCheckpointIds());
231
- * // -> [['0', '1'], '2', []]
232
- *
233
- * console.log(checkpoints.getCheckpoint('2'));
234
- * // -> 'sale'
235
- * ```
236
- * @category Setter
237
- */
238
- addCheckpoint(label?: string): Id;
239
-
240
- /**
241
- * The setCheckpoint method updates the label for a checkpoint in the
242
- * Checkpoints object after it has been created
243
- *
244
- * The `label` parameter can be used to describe the actions that changed the
245
- * Store before the given checkpoint. This can be useful for interfaces that
246
- * let users 'Undo [last action]'.
247
- *
248
- * Generally you will provide the `label` parameter when the addCheckpoint
249
- * method is called. Use this setCheckpoint method only when you need to
250
- * change the label at a later point.
251
- *
252
- * You cannot add a label to a checkpoint that does not yet exist.
253
- *
254
- * @param checkpointId The Id of the checkpoint to set the label for.
255
- * @param label A label to describe the actions leading up to this checkpoint
256
- * or left undefined if you want to clear the current label.
257
- * @returns A reference to the Checkpoints object.
258
- * @example
259
- * This example creates a Store, adds a Checkpoints object, and sets two
260
- * checkpoints, one with a label, which are both then re-labelled.
261
- *
262
- * ```js
263
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
264
- *
265
- * const checkpoints = createCheckpoints(store);
266
- * console.log(checkpoints.getCheckpointIds());
267
- * // -> [[], '0', []]
268
- *
269
- * store.setCell('pets', 'fido', 'species', 'dog');
270
- * checkpoints.addCheckpoint();
271
- * store.setCell('pets', 'fido', 'sold', true);
272
- * checkpoints.addCheckpoint('sale');
273
- *
274
- * console.log(checkpoints.getCheckpoint('1'));
275
- * // -> ''
276
- * console.log(checkpoints.getCheckpoint('2'));
277
- * // -> 'sale'
278
- *
279
- * checkpoints.setCheckpoint('1', 'identified');
280
- * checkpoints.setCheckpoint('2', '');
281
- *
282
- * console.log(checkpoints.getCheckpoint('1'));
283
- * // -> 'identified'
284
- * console.log(checkpoints.getCheckpoint('2'));
285
- * // -> ''
286
- *
287
- * checkpoints.setCheckpoint('3', 'unknown');
288
- * console.log(checkpoints.getCheckpoint('3'));
289
- * // -> undefined
290
- * ```
291
- * @category Setter
292
- */
293
- setCheckpoint(checkpointId: Id, label: string): Checkpoints;
294
-
295
- /**
296
- * The getStore method returns a reference to the underlying Store that is
297
- * backing this Checkpoints object.
298
- *
299
- * @returns A reference to the Store.
300
- * @example
301
- * This example creates a Checkpoints object against a newly-created Store
302
- * and then gets its reference in order to update its data and set a
303
- * checkpoint.
304
- *
305
- * ```js
306
- * const checkpoints = createCheckpoints(createStore());
307
- * checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
308
- * checkpoints.addCheckpoint();
309
- * console.log(checkpoints.getCheckpointIds());
310
- * // -> [['0'], '1', []]
311
- * ```
312
- * @category Getter
313
- */
314
- getStore(): Store;
315
-
316
- /**
317
- * The getCheckpointIds method returns an array of the checkpoint Ids being
318
- * managed by this Checkpoints object.
319
- *
320
- * The returned CheckpointIds array contains 'backward' checkpoint Ids, the
321
- * current checkpoint Id (if present), and the 'forward' checkpointIds.
322
- * Together, these are sufficient to understand the state of the Checkpoints
323
- * object and what movement is possible backward or forward through the
324
- * checkpoint stack.
325
- *
326
- * @returns A CheckpointIds array, containing the checkpoint Ids managed by
327
- * this Checkpoints object.
328
- * @example
329
- * This example creates a Store, adds a Checkpoints object, and then gets the
330
- * Ids of the checkpoints as it sets them and moves around the stack.
331
- *
332
- * ```js
333
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
334
- *
335
- * const checkpoints = createCheckpoints(store);
336
- * console.log(checkpoints.getCheckpointIds());
337
- * // -> [[], '0', []]
338
- *
339
- * store.setCell('pets', 'fido', 'sold', true);
340
- * checkpoints.addCheckpoint('sale');
341
- * console.log(checkpoints.getCheckpointIds());
342
- * // -> [['0'], '1', []]
343
- *
344
- * checkpoints.goBackward();
345
- * console.log(checkpoints.getCheckpointIds());
346
- * // -> [[], '0', ['1']]
347
- *
348
- * checkpoints.goForward();
349
- * console.log(checkpoints.getCheckpointIds());
350
- * // -> [['0'], '1', []]
351
- * ```
352
- * @category Getter
353
- */
354
- getCheckpointIds(): CheckpointIds;
355
-
356
- /**
357
- * The getCheckpoint method fetches the label for a checkpoint, if it had been
358
- * provided at the time of the addCheckpoint method or set subsequently with
359
- * the setCheckpoint method.
360
- *
361
- * If the checkpoint has had no label provided, this method will return an
362
- * empty string.
363
- *
364
- * @param checkpointId The Id of the checkpoint to get the label for.
365
- * @returns A string label for the requested checkpoint, an empty string if it
366
- * was never set, or `undefined` if the checkpoint does not exist.
367
- * @example
368
- * This example creates a Store, adds a Checkpoints object, and sets a
369
- * checkpoint with a label, before retrieving it again.
370
- *
371
- * ```js
372
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
373
- *
374
- * const checkpoints = createCheckpoints(store);
375
- * store.setCell('pets', 'fido', 'sold', true);
376
- * console.log(checkpoints.addCheckpoint('sale'));
377
- * // -> '1'
378
- *
379
- * console.log(checkpoints.getCheckpoint('1'));
380
- * // -> 'sale'
381
- * ```
382
- * @example
383
- * This example creates a Store, adds a Checkpoints object, and sets a
384
- * checkpoint without a label, setting it subsequently. A non-existent
385
- * checkpoint return an `undefined` label.
386
- *
387
- * ```js
388
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
389
- *
390
- * const checkpoints = createCheckpoints(store);
391
- * store.setCell('pets', 'fido', 'sold', true);
392
- * checkpoints.addCheckpoint();
393
- * console.log(checkpoints.getCheckpoint('1'));
394
- * // -> ''
395
- *
396
- * checkpoints.setCheckpoint('1', 'sold');
397
- * console.log(checkpoints.getCheckpoint('1'));
398
- * // -> 'sold'
399
- *
400
- * console.log(checkpoints.getCheckpoint('2'));
401
- * // -> undefined
402
- * ```
403
- * @category Getter
404
- */
405
- getCheckpoint(checkpointId: Id): string | undefined;
406
-
407
- /**
408
- * The addCheckpointIdsListener method registers a listener function with the
409
- * Checkpoints object that will be called whenever its set of checkpoints
410
- * changes.
411
- *
412
- * The provided listener is a CheckpointIdsListener function, and will be
413
- * called with a reference to the Checkpoints object.
414
- *
415
- * @param listener The function that will be called whenever the checkpoints
416
- * change.
417
- * @returns A unique Id for the listener that can later be used to remove it.
418
- * @example
419
- * This example creates a Store, a Checkpoints object, and then registers a
420
- * listener that responds to any changes to the checkpoints.
421
- *
422
- * ```js
423
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
424
- *
425
- * const checkpoints = createCheckpoints(store);
426
- * console.log(checkpoints.getCheckpointIds());
427
- * // -> [[], '0', []]
428
- *
429
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
430
- * console.log('Checkpoint Ids changed');
431
- * console.log(checkpoints.getCheckpointIds());
432
- * });
433
- *
434
- * store.setCell('pets', 'fido', 'species', 'dog');
435
- * // -> 'Checkpoint Ids changed'
436
- * // -> [['0'], undefined, []]
437
- *
438
- * checkpoints.addCheckpoint();
439
- * // -> 'Checkpoint Ids changed'
440
- * // -> [['0'], '1', []]
441
- *
442
- * checkpoints.goBackward();
443
- * // -> 'Checkpoint Ids changed'
444
- * // -> [[], '0', ['1']]
445
- *
446
- * checkpoints.goForward();
447
- * // -> 'Checkpoint Ids changed'
448
- * // -> [['0'], '1', []]
449
- *
450
- * checkpoints.delListener(listenerId);
451
- * checkpoints.destroy();
452
- * ```
453
- * @category Listener
454
- */
455
- addCheckpointIdsListener(listener: CheckpointIdsListener): Id;
456
-
457
- /**
458
- * The addCheckpointListener method registers a listener function with the
459
- * Checkpoints object that will be called whenever the label of a checkpoint
460
- * changes.
461
- *
462
- * You can either listen to a single checkpoint label (by specifying the
463
- * checkpoint Id as the method's first parameter), or changes to any
464
- * checkpoint label (by providing a `null` wildcard).
465
- *
466
- * The provided listener is a CheckpointListener function, and will be called
467
- * with a reference to the Checkpoints object, and the Id of the checkpoint
468
- * whose label changed.
469
- *
470
- * @param checkpointId The Id of the checkpoint to listen to, or `null` as a
471
- * wildcard.
472
- * @param listener The function that will be called whenever the checkpoint
473
- * label changes.
474
- * @returns A unique Id for the listener that can later be used to remove it.
475
- * @example
476
- * This example creates a Store, a Checkpoints object, and then registers a
477
- * listener that responds to any changes to a specific checkpoint label,
478
- * including when the checkpoint no longer exists.
479
- *
480
- * ```js
481
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
482
- *
483
- * const checkpoints = createCheckpoints(store);
484
- * console.log(checkpoints.getCheckpointIds());
485
- * // -> [[], '0', []]
486
- *
487
- * const listenerId = checkpoints.addCheckpointListener('1', () => {
488
- * console.log('Checkpoint 1 label changed');
489
- * console.log(checkpoints.getCheckpoint('1'));
490
- * });
491
- *
492
- * store.setCell('pets', 'fido', 'sold', true);
493
- * checkpoints.addCheckpoint('sale');
494
- * // -> 'Checkpoint 1 label changed'
495
- * // -> 'sale'
496
- *
497
- * checkpoints.setCheckpoint('1', 'sold');
498
- * // -> 'Checkpoint 1 label changed'
499
- * // -> 'sold'
500
- *
501
- * checkpoints.setCheckpoint('1', 'sold');
502
- * // The listener is not called when the label does not change.
503
- *
504
- * checkpoints.goTo('0');
505
- * store.setCell('pets', 'fido', 'sold', false);
506
- * // -> 'Checkpoint 1 label changed'
507
- * // -> undefined
508
- * // The checkpoint no longer exists.
509
- *
510
- * checkpoints.delListener(listenerId);
511
- * checkpoints.destroy();
512
- * ```
513
- * @category Listener
514
- */
515
- addCheckpointListener(
516
- checkpointId: IdOrNull,
517
- listener: CheckpointListener,
518
- ): Id;
519
-
520
- /**
521
- * The delListener method removes a listener that was previously added to the
522
- * Checkpoints object.
523
- *
524
- * Use the Id returned by the addCheckpointIdsListener method. Note that the
525
- * Checkpoints object may re-use this Id for future listeners added to it.
526
- *
527
- * @param listenerId The Id of the listener to remove.
528
- * @returns A reference to the Checkpoints object.
529
- * @example
530
- * This example creates a Store, a Checkpoints object, registers a listener,
531
- * and then removes it.
532
- *
533
- * ```js
534
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
535
- *
536
- * const checkpoints = createCheckpoints(store);
537
- * console.log(checkpoints.getCheckpointIds());
538
- * // -> [[], '0', []]
539
- *
540
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
541
- * console.log('checkpoints changed');
542
- * });
543
- *
544
- * store.setCell('pets', 'fido', 'species', 'dog');
545
- * // -> 'checkpoints changed'
546
- *
547
- * checkpoints.addCheckpoint();
548
- * // -> 'checkpoints changed'
549
- *
550
- * checkpoints.delListener(listenerId);
551
- *
552
- * store.setCell('pets', 'fido', 'sold', 'true');
553
- * // -> undefined
554
- * // The listener is not called.
555
- * ```
556
- * @category Listener
557
- */
558
- delListener(listenerId: Id): Checkpoints;
559
-
560
- /**
561
- * The goBackward method moves the state of the underlying Store back to the
562
- * previous checkpoint, effectively performing an 'undo' on the Store data.
563
- *
564
- * If there is no previous checkpoint to return to, this method has no effect.
565
- *
566
- * @returns A reference to the Checkpoints object.
567
- * @example
568
- * This example creates a Store, a Checkpoints object, makes a change and then
569
- * goes backward to the state of the Store before the change.
570
- *
571
- * ```js
572
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
573
- *
574
- * const checkpoints = createCheckpoints(store);
575
- * console.log(checkpoints.getCheckpointIds());
576
- * // -> [[], '0', []]
577
- *
578
- * store.setCell('pets', 'fido', 'sold', true);
579
- * checkpoints.addCheckpoint('sale');
580
- * console.log(checkpoints.getCheckpointIds());
581
- * // -> [['0'], '1', []]
582
- *
583
- * checkpoints.goBackward();
584
- * console.log(store.getCell('pets', 'fido', 'sold'));
585
- * // -> false
586
- * console.log(checkpoints.getCheckpointIds());
587
- * // -> [[], '0', ['1']]
588
- * ```
589
- * @category Movement
590
- */
591
- goBackward(): Checkpoints;
592
-
593
- /**
594
- * The goForward method moves the state of the underlying Store forwards to a
595
- * future checkpoint, effectively performing an 'redo' on the Store data.
596
- *
597
- * If there is no future checkpoint to return to, this method has no effect.
598
- *
599
- * Note that if you have previously used the goBackward method to undo
600
- * changes, the forwards 'redo' stack will only exist while you do not make
601
- * changes to the Store. In general the goForward method is expected to be
602
- * used to redo changes that were just undone.
603
- *
604
- * @returns A reference to the Checkpoints object.
605
- * @example
606
- * This example creates a Store, a Checkpoints object, makes a change and then
607
- * goes backward to the state of the Store before the change. It then goes
608
- * forward again to restore the state with the changes.
609
- *
610
- * ```js
611
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
612
- *
613
- * const checkpoints = createCheckpoints(store);
614
- * console.log(checkpoints.getCheckpointIds());
615
- * // -> [[], '0', []]
616
- *
617
- * store.setCell('pets', 'fido', 'sold', true);
618
- * checkpoints.addCheckpoint('sale');
619
- * console.log(checkpoints.getCheckpointIds());
620
- * // -> [['0'], '1', []]
621
- *
622
- * checkpoints.goBackward();
623
- * console.log(store.getCell('pets', 'fido', 'sold'));
624
- * // -> false
625
- * console.log(checkpoints.getCheckpointIds());
626
- * // -> [[], '0', ['1']]
627
- *
628
- * checkpoints.goForward();
629
- * console.log(store.getCell('pets', 'fido', 'sold'));
630
- * // -> true
631
- * console.log(checkpoints.getCheckpointIds());
632
- * // -> [['0'], '1', []]
633
- * ```
634
- * @example
635
- * This example creates a Store, a Checkpoints object, makes a change and then
636
- * goes backward to the state of the Store before the change. It makes a new
637
- * change, the redo stack disappears, and then the attempt to forward again
638
- * has no effect.
639
- *
640
- * ```js
641
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
642
- *
643
- * const checkpoints = createCheckpoints(store);
644
- * console.log(checkpoints.getCheckpointIds());
645
- * // -> [[], '0', []]
646
- *
647
- * store.setCell('pets', 'fido', 'sold', true);
648
- * checkpoints.addCheckpoint('sale');
649
- * console.log(checkpoints.getCheckpointIds());
650
- * // -> [['0'], '1', []]
651
- *
652
- * checkpoints.goBackward();
653
- * console.log(store.getCell('pets', 'fido', 'sold'));
654
- * // -> false
655
- * console.log(checkpoints.getCheckpointIds());
656
- * // -> [[], '0', ['1']]
657
- *
658
- * store.setCell('pets', 'fido', 'color', 'brown');
659
- * console.log(checkpoints.getCheckpointIds());
660
- * // -> [['0'], undefined, []]
661
- *
662
- * checkpoints.goForward();
663
- * console.log(store.getCell('pets', 'fido', 'sold'));
664
- * // -> false
665
- * console.log(checkpoints.getCheckpointIds());
666
- * // -> [['0'], undefined, []]
667
- * // The original change cannot be redone.
668
- * ```
669
- * @category Movement
670
- */
671
- goForward(): Checkpoints;
672
-
673
- /**
674
- * The goTo method moves the state of the underlying Store backwards or
675
- * forwards to a specified checkpoint.
676
- *
677
- * If there is no checkpoint with the Id specified, this method has no effect.
678
- *
679
- * @param checkpointId The Id of the checkpoint to move to.
680
- * @returns A reference to the Checkpoints object.
681
- * @example
682
- * This example creates a Store, a Checkpoints object, makes two changes and
683
- * then goes directly to the state of the Store before the two changes. It
684
- * then goes forward again one change, also using the goTo method. Finally it
685
- * tries to go to a checkpoint that does not exist.
686
- *
687
- * ```js
688
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
689
- *
690
- * const checkpoints = createCheckpoints(store);
691
- * console.log(checkpoints.getCheckpointIds());
692
- * // -> [[], '0', []]
693
- *
694
- * store.setCell('pets', 'fido', 'color', 'brown');
695
- * checkpoints.addCheckpoint('identification');
696
- * store.setCell('pets', 'fido', 'sold', true);
697
- * checkpoints.addCheckpoint('sale');
698
- * console.log(checkpoints.getCheckpointIds());
699
- * // -> [['0', '1'], '2', []]
700
- *
701
- * checkpoints.goTo('0');
702
- * console.log(store.getTables());
703
- * // -> {pets: {fido: {sold: false}}}
704
- * console.log(checkpoints.getCheckpointIds());
705
- * // -> [[], '0', ['1', '2']]
706
- *
707
- * checkpoints.goTo('1');
708
- * console.log(store.getTables());
709
- * // -> {pets: {fido: {sold: false, color: 'brown'}}}
710
- * console.log(checkpoints.getCheckpointIds());
711
- * // -> [['0'], '1', ['2']]
712
- *
713
- * checkpoints.goTo('3');
714
- * console.log(store.getTables());
715
- * // -> {pets: {fido: {sold: false, color: 'brown'}}}
716
- * console.log(checkpoints.getCheckpointIds());
717
- * // -> [['0'], '1', ['2']]
718
- * ```
719
- * @category Movement
720
- */
721
- goTo(checkpointId: Id): Checkpoints;
722
-
723
- /**
724
- * The clear method resets this Checkpoints object to its initial state,
725
- * removing all the checkpoints it has been managing.
726
- *
727
- * Obviously this method should be used with caution as it destroys the
728
- * ability to undo recent changes to the Store (though of course the Store
729
- * itself is not reset by this method).
730
- *
731
- * This method can be useful when a Store is being loaded via a Persister
732
- * asynchronously after the Checkpoints object has been attached, and you
733
- * don't want users to be able to undo the initial load of the data. In this
734
- * you could call the clear method immediately after the initial load so that
735
- * that is the baseline from which all subsequent changes are tracked.
736
- *
737
- * If you are listening to
738
- *
739
- * @returns A reference to the Checkpoints object.
740
- * @example
741
- * This example creates a Store, a Checkpoints object, adds a listener, makes
742
- * a change and then clears the checkpoints.
743
- *
744
- * ```js
745
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
746
- *
747
- * const checkpoints = createCheckpoints(store);
748
- * console.log(checkpoints.getCheckpointIds());
749
- * // -> [[], '0', []]
750
- *
751
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
752
- * console.log('checkpoints changed');
753
- * });
754
- *
755
- * store.setCell('pets', 'fido', 'color', 'brown');
756
- * // -> 'checkpoints changed'
757
- * checkpoints.addCheckpoint();
758
- * // -> 'checkpoints changed'
759
- * store.setCell('pets', 'fido', 'sold', true);
760
- * // -> 'checkpoints changed'
761
- * checkpoints.addCheckpoint();
762
- * // -> 'checkpoints changed'
763
- *
764
- * console.log(store.getTables());
765
- * // -> {pets: {fido: {sold: true, color: 'brown'}}}
766
- * console.log(checkpoints.getCheckpointIds());
767
- * // -> [['0', '1'], '2', []]
768
- *
769
- * checkpoints.clear();
770
- * // -> 'checkpoints changed'
771
- *
772
- * console.log(store.getTables());
773
- * // -> {pets: {fido: {sold: true, color: 'brown'}}}
774
- * console.log(checkpoints.getCheckpointIds());
775
- * // -> [[], '0', []]
776
- * ```
777
- * @category Lifecycle
778
- */
779
- clear(): Checkpoints;
780
-
781
- /**
782
- * The destroy method should be called when this Checkpoints object is no
783
- * longer used.
784
- *
785
- * This guarantees that all of the listeners that the object registered with
786
- * the underlying Store are removed and it can be correctly garbage collected.
787
- *
788
- * @example
789
- * This example creates a Store, adds a Checkpoints object (that registers a
790
- * CellListener with the underlying Store), and then destroys it again,
791
- * removing the listener.
792
- *
793
- * ```js
794
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
795
- *
796
- * const checkpoints = createCheckpoints(store);
797
- * console.log(store.getListenerStats().cell);
798
- * // -> 1
799
- *
800
- * checkpoints.destroy();
801
- *
802
- * console.log(store.getListenerStats().cell);
803
- * // -> 0
804
- * ```
805
- * @category Lifecycle
806
- */
807
- destroy(): void;
808
-
809
- /**
810
- * The getListenerStats method provides a set of statistics about the
811
- * listeners registered with the Checkpoints object, and is used for debugging
812
- * purposes.
813
- *
814
- * The CheckpointsListenerStats object contains a breakdown of the different
815
- * types of listener.
816
- *
817
- * The statistics are only populated in a debug build: production builds
818
- * return an empty object. The method is intended to be used during
819
- * development to ensure your application is not leaking listener
820
- * registrations, for example.
821
- *
822
- * @returns A CheckpointsListenerStats object containing Checkpoints listener
823
- * statistics.
824
- * @example
825
- * This example gets the listener statistics of a Checkpoints object.
826
- *
827
- * ```js
828
- * const store = createStore();
829
- * const checkpoints = createCheckpoints(store);
830
- * checkpoints.addCheckpointIdsListener(() => {
831
- * console.log('Checkpoint Ids changed');
832
- * });
833
- * checkpoints.addCheckpointListener(null, () => {
834
- * console.log('Checkpoint label changed');
835
- * });
836
- *
837
- * console.log(checkpoints.getListenerStats());
838
- * // -> {checkpointIds: 1, checkpoint: 1}
839
- * ```
840
- * @category Development
841
- */
842
- getListenerStats(): CheckpointsListenerStats;
843
- }
844
-
845
- /**
846
- * The createCheckpoints function creates a Checkpoints object, and is the main
847
- * entry point into the checkpoints module.
848
- *
849
- * It is trivially simple.
850
- *
851
- * A given Store can only have one Checkpoints object associated with it. If you
852
- * call this function twice on the same Store, your second call will return a
853
- * reference to the Checkpoints object created by the first.
854
- *
855
- * @param store The Store for which to set Checkpoints.
856
- * @returns A reference to the new Checkpoints object.
857
- * @example
858
- * This example creates a Checkpoints object.
859
- *
860
- * ```js
861
- * const store = createStore();
862
- * const checkpoints = createCheckpoints(store);
863
- * console.log(checkpoints.getCheckpointIds());
864
- * // -> [[], '0', []]
865
- * ```
866
- * @example
867
- * This example creates a Checkpoints object, and calls the method a second
868
- * time for the same Store to return the same object.
869
- *
870
- * ```js
871
- * const store = createStore();
872
- * const checkpoints1 = createCheckpoints(store);
873
- * const checkpoints2 = createCheckpoints(store);
874
- * console.log(checkpoints1 === checkpoints2);
875
- * // -> true
876
- * ```
877
- * @category Creation
878
- */
879
- export function createCheckpoints(store: Store): Checkpoints;