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