tinybase 0.9.2 → 1.0.1
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/LICENSE +1 -1
- package/lib/checkpoints.d.ts +38 -20
- package/lib/common.d.ts +56 -0
- package/lib/common.js +1 -0
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +38 -20
- package/lib/debug/common.d.ts +56 -0
- package/lib/debug/common.js +3 -0
- package/lib/debug/indexes.d.ts +39 -76
- package/lib/debug/indexes.js +17 -9
- package/lib/debug/metrics.d.ts +49 -20
- package/lib/debug/persisters.d.ts +207 -17
- package/lib/debug/relationships.d.ts +48 -23
- package/lib/debug/store.d.ts +184 -102
- package/lib/debug/tinybase.d.ts +1 -2
- package/lib/debug/tinybase.js +16 -8
- package/lib/debug/ui-react.d.ts +271 -163
- package/lib/debug/ui-react.js +24 -15
- package/lib/indexes.d.ts +39 -76
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +49 -20
- package/lib/persisters.d.ts +207 -17
- package/lib/relationships.d.ts +48 -23
- package/lib/store.d.ts +184 -102
- package/lib/tinybase.d.ts +1 -2
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +271 -163
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/common.js +1 -0
- package/lib/umd/common.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +24 -15
- package/readme.md +13 -13
package/LICENSE
CHANGED
package/lib/checkpoints.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type CheckpointIds = [Ids, Id | undefined, Ids];
|
|
|
43
43
|
* When called, a CheckpointIdsListener is given a reference to the Checkpoints
|
|
44
44
|
* object.
|
|
45
45
|
*
|
|
46
|
+
* @param checkpoints A reference to the Checkpoints object that changed.
|
|
46
47
|
* @category Listener
|
|
47
48
|
*/
|
|
48
49
|
export type CheckpointIdsListener = (checkpoints: Checkpoints) => void;
|
|
@@ -57,6 +58,8 @@ export type CheckpointIdsListener = (checkpoints: Checkpoints) => void;
|
|
|
57
58
|
* When called, a CheckpointListener is given a reference to the Checkpoints
|
|
58
59
|
* object, and the Id of the checkpoint whose label changed.
|
|
59
60
|
*
|
|
61
|
+
* @param checkpoints A reference to the Checkpoints object that changed.
|
|
62
|
+
* @param checkpointId The Id of the checkpoint that changed.
|
|
60
63
|
* @category Listener
|
|
61
64
|
*/
|
|
62
65
|
export type CheckpointListener = (
|
|
@@ -75,7 +78,14 @@ export type CheckpointListener = (
|
|
|
75
78
|
* @category Development
|
|
76
79
|
*/
|
|
77
80
|
export type CheckpointsListenerStats = {
|
|
81
|
+
/**
|
|
82
|
+
* The number of CheckpointIdsListeners registered with the Checkpoints
|
|
83
|
+
* object.
|
|
84
|
+
*/
|
|
78
85
|
checkpointIds?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The number of CheckpointListeners registered with the Checkpoints object.
|
|
88
|
+
*/
|
|
79
89
|
checkpoint?: number;
|
|
80
90
|
};
|
|
81
91
|
|
|
@@ -101,7 +111,7 @@ export type CheckpointsListenerStats = {
|
|
|
101
111
|
* to adding a checkpoint, getting the list of available checkpoints, and then
|
|
102
112
|
* registering and removing a listener for them.
|
|
103
113
|
*
|
|
104
|
-
* ```
|
|
114
|
+
* ```js
|
|
105
115
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
106
116
|
*
|
|
107
117
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -132,6 +142,10 @@ export type CheckpointsListenerStats = {
|
|
|
132
142
|
* checkpoints.delListener(listenerId);
|
|
133
143
|
* checkpoints.destroy();
|
|
134
144
|
* ```
|
|
145
|
+
* @see Relationships And Checkpoints guides
|
|
146
|
+
* @see Todo App demos
|
|
147
|
+
* @see TinyDraw demo
|
|
148
|
+
* @category Checkpoints
|
|
135
149
|
*/
|
|
136
150
|
export interface Checkpoints {
|
|
137
151
|
/**
|
|
@@ -151,7 +165,7 @@ export interface Checkpoints {
|
|
|
151
165
|
* of the Checkpoints object dramatically and then creates more than that
|
|
152
166
|
* number of checkpoints to demonstrate the oldest being pruned.
|
|
153
167
|
*
|
|
154
|
-
* ```
|
|
168
|
+
* ```js
|
|
155
169
|
* const store = createStore().setTables({pets: {fido: {views: 0}}});
|
|
156
170
|
*
|
|
157
171
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -196,7 +210,7 @@ export interface Checkpoints {
|
|
|
196
210
|
* This example creates a Store, adds a Checkpoints object, and adds two
|
|
197
211
|
* checkpoints, one with a label.
|
|
198
212
|
*
|
|
199
|
-
* ```
|
|
213
|
+
* ```js
|
|
200
214
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
201
215
|
*
|
|
202
216
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -245,7 +259,7 @@ export interface Checkpoints {
|
|
|
245
259
|
* This example creates a Store, adds a Checkpoints object, and sets two
|
|
246
260
|
* checkpoints, one with a label, which are both then re-labelled.
|
|
247
261
|
*
|
|
248
|
-
* ```
|
|
262
|
+
* ```js
|
|
249
263
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
250
264
|
*
|
|
251
265
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -288,7 +302,7 @@ export interface Checkpoints {
|
|
|
288
302
|
* and then gets its reference in order to update its data and set a
|
|
289
303
|
* checkpoint.
|
|
290
304
|
*
|
|
291
|
-
* ```
|
|
305
|
+
* ```js
|
|
292
306
|
* const checkpoints = createCheckpoints(createStore());
|
|
293
307
|
* checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
|
|
294
308
|
* checkpoints.addCheckpoint();
|
|
@@ -315,7 +329,7 @@ export interface Checkpoints {
|
|
|
315
329
|
* This example creates a Store, adds a Checkpoints object, and then gets the
|
|
316
330
|
* Ids of the checkpoints as it sets them and moves around the stack.
|
|
317
331
|
*
|
|
318
|
-
* ```
|
|
332
|
+
* ```js
|
|
319
333
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
320
334
|
*
|
|
321
335
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -354,7 +368,7 @@ export interface Checkpoints {
|
|
|
354
368
|
* This example creates a Store, adds a Checkpoints object, and sets a
|
|
355
369
|
* checkpoint with a label, before retrieving it again.
|
|
356
370
|
*
|
|
357
|
-
* ```
|
|
371
|
+
* ```js
|
|
358
372
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
359
373
|
*
|
|
360
374
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -370,7 +384,7 @@ export interface Checkpoints {
|
|
|
370
384
|
* checkpoint without a label, setting it subsequently. A non-existent
|
|
371
385
|
* checkpoint return an `undefined` label.
|
|
372
386
|
*
|
|
373
|
-
* ```
|
|
387
|
+
* ```js
|
|
374
388
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
375
389
|
*
|
|
376
390
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -405,7 +419,7 @@ export interface Checkpoints {
|
|
|
405
419
|
* This example creates a Store, a Checkpoints object, and then registers a
|
|
406
420
|
* listener that responds to any changes to the checkpoints.
|
|
407
421
|
*
|
|
408
|
-
* ```
|
|
422
|
+
* ```js
|
|
409
423
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
410
424
|
*
|
|
411
425
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -463,7 +477,7 @@ export interface Checkpoints {
|
|
|
463
477
|
* listener that responds to any changes to a specific checkpoint label,
|
|
464
478
|
* including when the checkpoint no longer exists.
|
|
465
479
|
*
|
|
466
|
-
* ```
|
|
480
|
+
* ```js
|
|
467
481
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
468
482
|
*
|
|
469
483
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -516,7 +530,7 @@ export interface Checkpoints {
|
|
|
516
530
|
* This example creates a Store, a Checkpoints object, registers a listener,
|
|
517
531
|
* and then removes it.
|
|
518
532
|
*
|
|
519
|
-
* ```
|
|
533
|
+
* ```js
|
|
520
534
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
521
535
|
*
|
|
522
536
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -554,7 +568,7 @@ export interface Checkpoints {
|
|
|
554
568
|
* This example creates a Store, a Checkpoints object, makes a change and then
|
|
555
569
|
* goes backward to the state of the Store before the change.
|
|
556
570
|
*
|
|
557
|
-
* ```
|
|
571
|
+
* ```js
|
|
558
572
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
559
573
|
*
|
|
560
574
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -572,6 +586,7 @@ export interface Checkpoints {
|
|
|
572
586
|
* console.log(checkpoints.getCheckpointIds());
|
|
573
587
|
* // -> [[], '0', ['1']]
|
|
574
588
|
* ```
|
|
589
|
+
* @category Movement
|
|
575
590
|
*/
|
|
576
591
|
goBackward(): Checkpoints;
|
|
577
592
|
|
|
@@ -592,7 +607,7 @@ export interface Checkpoints {
|
|
|
592
607
|
* goes backward to the state of the Store before the change. It then goes
|
|
593
608
|
* forward again to restore the state with the changes.
|
|
594
609
|
*
|
|
595
|
-
* ```
|
|
610
|
+
* ```js
|
|
596
611
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
597
612
|
*
|
|
598
613
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -622,7 +637,7 @@ export interface Checkpoints {
|
|
|
622
637
|
* change, the redo stack disappears, and then the attempt to forward again
|
|
623
638
|
* has no effect.
|
|
624
639
|
*
|
|
625
|
-
* ```
|
|
640
|
+
* ```js
|
|
626
641
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
627
642
|
*
|
|
628
643
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -651,6 +666,7 @@ export interface Checkpoints {
|
|
|
651
666
|
* // -> [['0'], undefined, []]
|
|
652
667
|
* // The original change cannot be redone.
|
|
653
668
|
* ```
|
|
669
|
+
* @category Movement
|
|
654
670
|
*/
|
|
655
671
|
goForward(): Checkpoints;
|
|
656
672
|
|
|
@@ -668,7 +684,7 @@ export interface Checkpoints {
|
|
|
668
684
|
* then goes forward again one change, also using the goTo method. Finally it
|
|
669
685
|
* tries to go to a checkpoint that does not exist.
|
|
670
686
|
*
|
|
671
|
-
* ```
|
|
687
|
+
* ```js
|
|
672
688
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
673
689
|
*
|
|
674
690
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -700,6 +716,7 @@ export interface Checkpoints {
|
|
|
700
716
|
* console.log(checkpoints.getCheckpointIds());
|
|
701
717
|
* // -> [['0'], '1', ['2']]
|
|
702
718
|
* ```
|
|
719
|
+
* @category Movement
|
|
703
720
|
*/
|
|
704
721
|
goTo(checkpointId: Id): Checkpoints;
|
|
705
722
|
|
|
@@ -724,7 +741,7 @@ export interface Checkpoints {
|
|
|
724
741
|
* This example creates a Store, a Checkpoints object, adds a listener, makes
|
|
725
742
|
* a change and then clears the checkpoints.
|
|
726
743
|
*
|
|
727
|
-
* ```
|
|
744
|
+
* ```js
|
|
728
745
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
729
746
|
*
|
|
730
747
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -773,7 +790,7 @@ export interface Checkpoints {
|
|
|
773
790
|
* CellListener with the underlying Store), and then destroys it again,
|
|
774
791
|
* removing the listener.
|
|
775
792
|
*
|
|
776
|
-
* ```
|
|
793
|
+
* ```js
|
|
777
794
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
778
795
|
*
|
|
779
796
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -807,7 +824,7 @@ export interface Checkpoints {
|
|
|
807
824
|
* @example
|
|
808
825
|
* This example gets the listener statistics of a Checkpoints object.
|
|
809
826
|
*
|
|
810
|
-
* ```
|
|
827
|
+
* ```js
|
|
811
828
|
* const store = createStore();
|
|
812
829
|
* const checkpoints = createCheckpoints(store);
|
|
813
830
|
* checkpoints.addCheckpointIdsListener(() => {
|
|
@@ -840,7 +857,7 @@ export interface Checkpoints {
|
|
|
840
857
|
* @example
|
|
841
858
|
* This example creates a Checkpoints object.
|
|
842
859
|
*
|
|
843
|
-
* ```
|
|
860
|
+
* ```js
|
|
844
861
|
* const store = createStore();
|
|
845
862
|
* const checkpoints = createCheckpoints(store);
|
|
846
863
|
* console.log(checkpoints.getCheckpointIds());
|
|
@@ -850,12 +867,13 @@ export interface Checkpoints {
|
|
|
850
867
|
* This example creates a Checkpoints object, and calls the method a second
|
|
851
868
|
* time for the same Store to return the same object.
|
|
852
869
|
*
|
|
853
|
-
* ```
|
|
870
|
+
* ```js
|
|
854
871
|
* const store = createStore();
|
|
855
872
|
* const checkpoints1 = createCheckpoints(store);
|
|
856
873
|
* const checkpoints2 = createCheckpoints(store);
|
|
857
874
|
* console.log(checkpoints1 === checkpoints2);
|
|
858
875
|
* // -> true
|
|
859
876
|
* ```
|
|
877
|
+
* @category Creation
|
|
860
878
|
*/
|
|
861
879
|
export function createCheckpoints(store: Store): Checkpoints;
|
package/lib/common.d.ts
CHANGED
|
@@ -57,3 +57,59 @@ export type ParameterizedCallback<Parameter> = (parameter?: Parameter) => void;
|
|
|
57
57
|
* @category Callback
|
|
58
58
|
*/
|
|
59
59
|
export type Callback = () => void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The SortKey type represents a value that can be used by a sort function.
|
|
63
|
+
*
|
|
64
|
+
* @category Parameter
|
|
65
|
+
*/
|
|
66
|
+
export type SortKey = string | number | boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The defaultSorter function is provided as a convenience to sort keys
|
|
70
|
+
* alphanumerically, and can be provided to the `sliceIdSorter` and
|
|
71
|
+
* `rowIdSorter` parameters of the setIndexDefinition method in the indexes
|
|
72
|
+
* module, for example.
|
|
73
|
+
*
|
|
74
|
+
* @param sortKey1 The first item of the pair to compare.
|
|
75
|
+
* @param sortKey2 The second item of the pair to compare.
|
|
76
|
+
* @returns A number indicating how to sort the pair.
|
|
77
|
+
* @example
|
|
78
|
+
* This example creates an Indexes object.
|
|
79
|
+
*
|
|
80
|
+
* ```js
|
|
81
|
+
* const store = createStore();
|
|
82
|
+
* const indexes = createIndexes(store);
|
|
83
|
+
* console.log(indexes.getIndexIds());
|
|
84
|
+
* // -> []
|
|
85
|
+
* ```
|
|
86
|
+
* @example
|
|
87
|
+
* This example creates a Store, creates an Indexes object, and defines an
|
|
88
|
+
* Index based on the first letter of the pets' names. The Slice Ids (and Row
|
|
89
|
+
* Ids within them) are alphabetically sorted using the defaultSorter function.
|
|
90
|
+
*
|
|
91
|
+
* ```js
|
|
92
|
+
* const store = createStore().setTable('pets', {
|
|
93
|
+
* fido: {species: 'dog'},
|
|
94
|
+
* felix: {species: 'cat'},
|
|
95
|
+
* cujo: {species: 'dog'},
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* const indexes = createIndexes(store);
|
|
99
|
+
* indexes.setIndexDefinition(
|
|
100
|
+
* 'byFirst', // indexId
|
|
101
|
+
* 'pets', // tableId
|
|
102
|
+
* (_, rowId) => rowId[0], // each Row's Slice Id
|
|
103
|
+
* (_, rowId) => rowId, // each Row's sort key
|
|
104
|
+
* defaultSorter, // sort Slice Ids
|
|
105
|
+
* defaultSorter, // sort Row Ids by sort key
|
|
106
|
+
* );
|
|
107
|
+
*
|
|
108
|
+
* console.log(indexes.getSliceIds('byFirst'));
|
|
109
|
+
* // -> ['c', 'f']
|
|
110
|
+
* console.log(indexes.getSliceRowIds('byFirst', 'f'));
|
|
111
|
+
* // -> ['felix', 'fido']
|
|
112
|
+
* ```
|
|
113
|
+
* @category Convenience
|
|
114
|
+
*/
|
|
115
|
+
export function defaultSorter(sortKey1: SortKey, sortKey2: SortKey): number;
|
package/lib/common.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=(o,t)=>o<t?-1:1;export{o as defaultSorter};
|
package/lib/common.js.gz
ADDED
|
Binary file
|
|
@@ -43,6 +43,7 @@ export type CheckpointIds = [Ids, Id | undefined, Ids];
|
|
|
43
43
|
* When called, a CheckpointIdsListener is given a reference to the Checkpoints
|
|
44
44
|
* object.
|
|
45
45
|
*
|
|
46
|
+
* @param checkpoints A reference to the Checkpoints object that changed.
|
|
46
47
|
* @category Listener
|
|
47
48
|
*/
|
|
48
49
|
export type CheckpointIdsListener = (checkpoints: Checkpoints) => void;
|
|
@@ -57,6 +58,8 @@ export type CheckpointIdsListener = (checkpoints: Checkpoints) => void;
|
|
|
57
58
|
* When called, a CheckpointListener is given a reference to the Checkpoints
|
|
58
59
|
* object, and the Id of the checkpoint whose label changed.
|
|
59
60
|
*
|
|
61
|
+
* @param checkpoints A reference to the Checkpoints object that changed.
|
|
62
|
+
* @param checkpointId The Id of the checkpoint that changed.
|
|
60
63
|
* @category Listener
|
|
61
64
|
*/
|
|
62
65
|
export type CheckpointListener = (
|
|
@@ -75,7 +78,14 @@ export type CheckpointListener = (
|
|
|
75
78
|
* @category Development
|
|
76
79
|
*/
|
|
77
80
|
export type CheckpointsListenerStats = {
|
|
81
|
+
/**
|
|
82
|
+
* The number of CheckpointIdsListeners registered with the Checkpoints
|
|
83
|
+
* object.
|
|
84
|
+
*/
|
|
78
85
|
checkpointIds?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The number of CheckpointListeners registered with the Checkpoints object.
|
|
88
|
+
*/
|
|
79
89
|
checkpoint?: number;
|
|
80
90
|
};
|
|
81
91
|
|
|
@@ -101,7 +111,7 @@ export type CheckpointsListenerStats = {
|
|
|
101
111
|
* to adding a checkpoint, getting the list of available checkpoints, and then
|
|
102
112
|
* registering and removing a listener for them.
|
|
103
113
|
*
|
|
104
|
-
* ```
|
|
114
|
+
* ```js
|
|
105
115
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
106
116
|
*
|
|
107
117
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -132,6 +142,10 @@ export type CheckpointsListenerStats = {
|
|
|
132
142
|
* checkpoints.delListener(listenerId);
|
|
133
143
|
* checkpoints.destroy();
|
|
134
144
|
* ```
|
|
145
|
+
* @see Relationships And Checkpoints guides
|
|
146
|
+
* @see Todo App demos
|
|
147
|
+
* @see TinyDraw demo
|
|
148
|
+
* @category Checkpoints
|
|
135
149
|
*/
|
|
136
150
|
export interface Checkpoints {
|
|
137
151
|
/**
|
|
@@ -151,7 +165,7 @@ export interface Checkpoints {
|
|
|
151
165
|
* of the Checkpoints object dramatically and then creates more than that
|
|
152
166
|
* number of checkpoints to demonstrate the oldest being pruned.
|
|
153
167
|
*
|
|
154
|
-
* ```
|
|
168
|
+
* ```js
|
|
155
169
|
* const store = createStore().setTables({pets: {fido: {views: 0}}});
|
|
156
170
|
*
|
|
157
171
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -196,7 +210,7 @@ export interface Checkpoints {
|
|
|
196
210
|
* This example creates a Store, adds a Checkpoints object, and adds two
|
|
197
211
|
* checkpoints, one with a label.
|
|
198
212
|
*
|
|
199
|
-
* ```
|
|
213
|
+
* ```js
|
|
200
214
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
201
215
|
*
|
|
202
216
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -245,7 +259,7 @@ export interface Checkpoints {
|
|
|
245
259
|
* This example creates a Store, adds a Checkpoints object, and sets two
|
|
246
260
|
* checkpoints, one with a label, which are both then re-labelled.
|
|
247
261
|
*
|
|
248
|
-
* ```
|
|
262
|
+
* ```js
|
|
249
263
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
250
264
|
*
|
|
251
265
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -288,7 +302,7 @@ export interface Checkpoints {
|
|
|
288
302
|
* and then gets its reference in order to update its data and set a
|
|
289
303
|
* checkpoint.
|
|
290
304
|
*
|
|
291
|
-
* ```
|
|
305
|
+
* ```js
|
|
292
306
|
* const checkpoints = createCheckpoints(createStore());
|
|
293
307
|
* checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
|
|
294
308
|
* checkpoints.addCheckpoint();
|
|
@@ -315,7 +329,7 @@ export interface Checkpoints {
|
|
|
315
329
|
* This example creates a Store, adds a Checkpoints object, and then gets the
|
|
316
330
|
* Ids of the checkpoints as it sets them and moves around the stack.
|
|
317
331
|
*
|
|
318
|
-
* ```
|
|
332
|
+
* ```js
|
|
319
333
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
320
334
|
*
|
|
321
335
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -354,7 +368,7 @@ export interface Checkpoints {
|
|
|
354
368
|
* This example creates a Store, adds a Checkpoints object, and sets a
|
|
355
369
|
* checkpoint with a label, before retrieving it again.
|
|
356
370
|
*
|
|
357
|
-
* ```
|
|
371
|
+
* ```js
|
|
358
372
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
359
373
|
*
|
|
360
374
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -370,7 +384,7 @@ export interface Checkpoints {
|
|
|
370
384
|
* checkpoint without a label, setting it subsequently. A non-existent
|
|
371
385
|
* checkpoint return an `undefined` label.
|
|
372
386
|
*
|
|
373
|
-
* ```
|
|
387
|
+
* ```js
|
|
374
388
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
375
389
|
*
|
|
376
390
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -405,7 +419,7 @@ export interface Checkpoints {
|
|
|
405
419
|
* This example creates a Store, a Checkpoints object, and then registers a
|
|
406
420
|
* listener that responds to any changes to the checkpoints.
|
|
407
421
|
*
|
|
408
|
-
* ```
|
|
422
|
+
* ```js
|
|
409
423
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
410
424
|
*
|
|
411
425
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -463,7 +477,7 @@ export interface Checkpoints {
|
|
|
463
477
|
* listener that responds to any changes to a specific checkpoint label,
|
|
464
478
|
* including when the checkpoint no longer exists.
|
|
465
479
|
*
|
|
466
|
-
* ```
|
|
480
|
+
* ```js
|
|
467
481
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
468
482
|
*
|
|
469
483
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -516,7 +530,7 @@ export interface Checkpoints {
|
|
|
516
530
|
* This example creates a Store, a Checkpoints object, registers a listener,
|
|
517
531
|
* and then removes it.
|
|
518
532
|
*
|
|
519
|
-
* ```
|
|
533
|
+
* ```js
|
|
520
534
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
521
535
|
*
|
|
522
536
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -554,7 +568,7 @@ export interface Checkpoints {
|
|
|
554
568
|
* This example creates a Store, a Checkpoints object, makes a change and then
|
|
555
569
|
* goes backward to the state of the Store before the change.
|
|
556
570
|
*
|
|
557
|
-
* ```
|
|
571
|
+
* ```js
|
|
558
572
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
559
573
|
*
|
|
560
574
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -572,6 +586,7 @@ export interface Checkpoints {
|
|
|
572
586
|
* console.log(checkpoints.getCheckpointIds());
|
|
573
587
|
* // -> [[], '0', ['1']]
|
|
574
588
|
* ```
|
|
589
|
+
* @category Movement
|
|
575
590
|
*/
|
|
576
591
|
goBackward(): Checkpoints;
|
|
577
592
|
|
|
@@ -592,7 +607,7 @@ export interface Checkpoints {
|
|
|
592
607
|
* goes backward to the state of the Store before the change. It then goes
|
|
593
608
|
* forward again to restore the state with the changes.
|
|
594
609
|
*
|
|
595
|
-
* ```
|
|
610
|
+
* ```js
|
|
596
611
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
597
612
|
*
|
|
598
613
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -622,7 +637,7 @@ export interface Checkpoints {
|
|
|
622
637
|
* change, the redo stack disappears, and then the attempt to forward again
|
|
623
638
|
* has no effect.
|
|
624
639
|
*
|
|
625
|
-
* ```
|
|
640
|
+
* ```js
|
|
626
641
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
627
642
|
*
|
|
628
643
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -651,6 +666,7 @@ export interface Checkpoints {
|
|
|
651
666
|
* // -> [['0'], undefined, []]
|
|
652
667
|
* // The original change cannot be redone.
|
|
653
668
|
* ```
|
|
669
|
+
* @category Movement
|
|
654
670
|
*/
|
|
655
671
|
goForward(): Checkpoints;
|
|
656
672
|
|
|
@@ -668,7 +684,7 @@ export interface Checkpoints {
|
|
|
668
684
|
* then goes forward again one change, also using the goTo method. Finally it
|
|
669
685
|
* tries to go to a checkpoint that does not exist.
|
|
670
686
|
*
|
|
671
|
-
* ```
|
|
687
|
+
* ```js
|
|
672
688
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
673
689
|
*
|
|
674
690
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -700,6 +716,7 @@ export interface Checkpoints {
|
|
|
700
716
|
* console.log(checkpoints.getCheckpointIds());
|
|
701
717
|
* // -> [['0'], '1', ['2']]
|
|
702
718
|
* ```
|
|
719
|
+
* @category Movement
|
|
703
720
|
*/
|
|
704
721
|
goTo(checkpointId: Id): Checkpoints;
|
|
705
722
|
|
|
@@ -724,7 +741,7 @@ export interface Checkpoints {
|
|
|
724
741
|
* This example creates a Store, a Checkpoints object, adds a listener, makes
|
|
725
742
|
* a change and then clears the checkpoints.
|
|
726
743
|
*
|
|
727
|
-
* ```
|
|
744
|
+
* ```js
|
|
728
745
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
729
746
|
*
|
|
730
747
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -773,7 +790,7 @@ export interface Checkpoints {
|
|
|
773
790
|
* CellListener with the underlying Store), and then destroys it again,
|
|
774
791
|
* removing the listener.
|
|
775
792
|
*
|
|
776
|
-
* ```
|
|
793
|
+
* ```js
|
|
777
794
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
778
795
|
*
|
|
779
796
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -807,7 +824,7 @@ export interface Checkpoints {
|
|
|
807
824
|
* @example
|
|
808
825
|
* This example gets the listener statistics of a Checkpoints object.
|
|
809
826
|
*
|
|
810
|
-
* ```
|
|
827
|
+
* ```js
|
|
811
828
|
* const store = createStore();
|
|
812
829
|
* const checkpoints = createCheckpoints(store);
|
|
813
830
|
* checkpoints.addCheckpointIdsListener(() => {
|
|
@@ -840,7 +857,7 @@ export interface Checkpoints {
|
|
|
840
857
|
* @example
|
|
841
858
|
* This example creates a Checkpoints object.
|
|
842
859
|
*
|
|
843
|
-
* ```
|
|
860
|
+
* ```js
|
|
844
861
|
* const store = createStore();
|
|
845
862
|
* const checkpoints = createCheckpoints(store);
|
|
846
863
|
* console.log(checkpoints.getCheckpointIds());
|
|
@@ -850,12 +867,13 @@ export interface Checkpoints {
|
|
|
850
867
|
* This example creates a Checkpoints object, and calls the method a second
|
|
851
868
|
* time for the same Store to return the same object.
|
|
852
869
|
*
|
|
853
|
-
* ```
|
|
870
|
+
* ```js
|
|
854
871
|
* const store = createStore();
|
|
855
872
|
* const checkpoints1 = createCheckpoints(store);
|
|
856
873
|
* const checkpoints2 = createCheckpoints(store);
|
|
857
874
|
* console.log(checkpoints1 === checkpoints2);
|
|
858
875
|
* // -> true
|
|
859
876
|
* ```
|
|
877
|
+
* @category Creation
|
|
860
878
|
*/
|
|
861
879
|
export function createCheckpoints(store: Store): Checkpoints;
|
package/lib/debug/common.d.ts
CHANGED
|
@@ -57,3 +57,59 @@ export type ParameterizedCallback<Parameter> = (parameter?: Parameter) => void;
|
|
|
57
57
|
* @category Callback
|
|
58
58
|
*/
|
|
59
59
|
export type Callback = () => void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The SortKey type represents a value that can be used by a sort function.
|
|
63
|
+
*
|
|
64
|
+
* @category Parameter
|
|
65
|
+
*/
|
|
66
|
+
export type SortKey = string | number | boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The defaultSorter function is provided as a convenience to sort keys
|
|
70
|
+
* alphanumerically, and can be provided to the `sliceIdSorter` and
|
|
71
|
+
* `rowIdSorter` parameters of the setIndexDefinition method in the indexes
|
|
72
|
+
* module, for example.
|
|
73
|
+
*
|
|
74
|
+
* @param sortKey1 The first item of the pair to compare.
|
|
75
|
+
* @param sortKey2 The second item of the pair to compare.
|
|
76
|
+
* @returns A number indicating how to sort the pair.
|
|
77
|
+
* @example
|
|
78
|
+
* This example creates an Indexes object.
|
|
79
|
+
*
|
|
80
|
+
* ```js
|
|
81
|
+
* const store = createStore();
|
|
82
|
+
* const indexes = createIndexes(store);
|
|
83
|
+
* console.log(indexes.getIndexIds());
|
|
84
|
+
* // -> []
|
|
85
|
+
* ```
|
|
86
|
+
* @example
|
|
87
|
+
* This example creates a Store, creates an Indexes object, and defines an
|
|
88
|
+
* Index based on the first letter of the pets' names. The Slice Ids (and Row
|
|
89
|
+
* Ids within them) are alphabetically sorted using the defaultSorter function.
|
|
90
|
+
*
|
|
91
|
+
* ```js
|
|
92
|
+
* const store = createStore().setTable('pets', {
|
|
93
|
+
* fido: {species: 'dog'},
|
|
94
|
+
* felix: {species: 'cat'},
|
|
95
|
+
* cujo: {species: 'dog'},
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* const indexes = createIndexes(store);
|
|
99
|
+
* indexes.setIndexDefinition(
|
|
100
|
+
* 'byFirst', // indexId
|
|
101
|
+
* 'pets', // tableId
|
|
102
|
+
* (_, rowId) => rowId[0], // each Row's Slice Id
|
|
103
|
+
* (_, rowId) => rowId, // each Row's sort key
|
|
104
|
+
* defaultSorter, // sort Slice Ids
|
|
105
|
+
* defaultSorter, // sort Row Ids by sort key
|
|
106
|
+
* );
|
|
107
|
+
*
|
|
108
|
+
* console.log(indexes.getSliceIds('byFirst'));
|
|
109
|
+
* // -> ['c', 'f']
|
|
110
|
+
* console.log(indexes.getSliceRowIds('byFirst', 'f'));
|
|
111
|
+
* // -> ['felix', 'fido']
|
|
112
|
+
* ```
|
|
113
|
+
* @category Convenience
|
|
114
|
+
*/
|
|
115
|
+
export function defaultSorter(sortKey1: SortKey, sortKey2: SortKey): number;
|