tinybase 0.9.0 → 0.9.4
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/checkpoints.d.ts +35 -20
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- 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 +35 -20
- package/lib/debug/checkpoints.js +1 -1
- package/lib/debug/common.d.ts +56 -0
- package/lib/debug/common.js +3 -0
- package/lib/debug/indexes.d.ts +35 -76
- package/lib/debug/indexes.js +18 -10
- package/lib/debug/metrics.d.ts +45 -20
- package/lib/debug/metrics.js +1 -1
- package/lib/debug/persisters.d.ts +203 -17
- package/lib/debug/persisters.js +1 -1
- package/lib/debug/relationships.d.ts +46 -23
- package/lib/debug/relationships.js +1 -1
- package/lib/debug/store.d.ts +179 -102
- package/lib/debug/store.js +1 -1
- package/lib/debug/tinybase.d.ts +1 -2
- package/lib/debug/tinybase.js +18 -1029
- package/lib/debug/{react.d.ts → ui-react.d.ts} +262 -162
- package/lib/debug/{react.js → ui-react.js} +24 -15
- package/lib/indexes.d.ts +35 -76
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +45 -20
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +203 -17
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.d.ts +46 -23
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +179 -102
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +1 -2
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/{react.d.ts → ui-react.d.ts} +262 -162
- package/lib/ui-react.js +1 -0
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.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/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -0
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +21 -16
- package/readme.md +13 -13
- package/lib/react.js +0 -1
- package/lib/react.js.gz +0 -0
- package/lib/umd/react.js +0 -1
- package/lib/umd/react.js.gz +0 -0
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,7 @@ export type CheckpointsListenerStats = {
|
|
|
132
142
|
* checkpoints.delListener(listenerId);
|
|
133
143
|
* checkpoints.destroy();
|
|
134
144
|
* ```
|
|
145
|
+
* @category Checkpoints
|
|
135
146
|
*/
|
|
136
147
|
export interface Checkpoints {
|
|
137
148
|
/**
|
|
@@ -151,7 +162,7 @@ export interface Checkpoints {
|
|
|
151
162
|
* of the Checkpoints object dramatically and then creates more than that
|
|
152
163
|
* number of checkpoints to demonstrate the oldest being pruned.
|
|
153
164
|
*
|
|
154
|
-
* ```
|
|
165
|
+
* ```js
|
|
155
166
|
* const store = createStore().setTables({pets: {fido: {views: 0}}});
|
|
156
167
|
*
|
|
157
168
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -196,7 +207,7 @@ export interface Checkpoints {
|
|
|
196
207
|
* This example creates a Store, adds a Checkpoints object, and adds two
|
|
197
208
|
* checkpoints, one with a label.
|
|
198
209
|
*
|
|
199
|
-
* ```
|
|
210
|
+
* ```js
|
|
200
211
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
201
212
|
*
|
|
202
213
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -245,7 +256,7 @@ export interface Checkpoints {
|
|
|
245
256
|
* This example creates a Store, adds a Checkpoints object, and sets two
|
|
246
257
|
* checkpoints, one with a label, which are both then re-labelled.
|
|
247
258
|
*
|
|
248
|
-
* ```
|
|
259
|
+
* ```js
|
|
249
260
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
250
261
|
*
|
|
251
262
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -288,7 +299,7 @@ export interface Checkpoints {
|
|
|
288
299
|
* and then gets its reference in order to update its data and set a
|
|
289
300
|
* checkpoint.
|
|
290
301
|
*
|
|
291
|
-
* ```
|
|
302
|
+
* ```js
|
|
292
303
|
* const checkpoints = createCheckpoints(createStore());
|
|
293
304
|
* checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
|
|
294
305
|
* checkpoints.addCheckpoint();
|
|
@@ -315,7 +326,7 @@ export interface Checkpoints {
|
|
|
315
326
|
* This example creates a Store, adds a Checkpoints object, and then gets the
|
|
316
327
|
* Ids of the checkpoints as it sets them and moves around the stack.
|
|
317
328
|
*
|
|
318
|
-
* ```
|
|
329
|
+
* ```js
|
|
319
330
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
320
331
|
*
|
|
321
332
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -354,7 +365,7 @@ export interface Checkpoints {
|
|
|
354
365
|
* This example creates a Store, adds a Checkpoints object, and sets a
|
|
355
366
|
* checkpoint with a label, before retrieving it again.
|
|
356
367
|
*
|
|
357
|
-
* ```
|
|
368
|
+
* ```js
|
|
358
369
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
359
370
|
*
|
|
360
371
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -370,7 +381,7 @@ export interface Checkpoints {
|
|
|
370
381
|
* checkpoint without a label, setting it subsequently. A non-existent
|
|
371
382
|
* checkpoint return an `undefined` label.
|
|
372
383
|
*
|
|
373
|
-
* ```
|
|
384
|
+
* ```js
|
|
374
385
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
375
386
|
*
|
|
376
387
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -405,7 +416,7 @@ export interface Checkpoints {
|
|
|
405
416
|
* This example creates a Store, a Checkpoints object, and then registers a
|
|
406
417
|
* listener that responds to any changes to the checkpoints.
|
|
407
418
|
*
|
|
408
|
-
* ```
|
|
419
|
+
* ```js
|
|
409
420
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
410
421
|
*
|
|
411
422
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -463,7 +474,7 @@ export interface Checkpoints {
|
|
|
463
474
|
* listener that responds to any changes to a specific checkpoint label,
|
|
464
475
|
* including when the checkpoint no longer exists.
|
|
465
476
|
*
|
|
466
|
-
* ```
|
|
477
|
+
* ```js
|
|
467
478
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
468
479
|
*
|
|
469
480
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -516,7 +527,7 @@ export interface Checkpoints {
|
|
|
516
527
|
* This example creates a Store, a Checkpoints object, registers a listener,
|
|
517
528
|
* and then removes it.
|
|
518
529
|
*
|
|
519
|
-
* ```
|
|
530
|
+
* ```js
|
|
520
531
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
521
532
|
*
|
|
522
533
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -554,7 +565,7 @@ export interface Checkpoints {
|
|
|
554
565
|
* This example creates a Store, a Checkpoints object, makes a change and then
|
|
555
566
|
* goes backward to the state of the Store before the change.
|
|
556
567
|
*
|
|
557
|
-
* ```
|
|
568
|
+
* ```js
|
|
558
569
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
559
570
|
*
|
|
560
571
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -572,6 +583,7 @@ export interface Checkpoints {
|
|
|
572
583
|
* console.log(checkpoints.getCheckpointIds());
|
|
573
584
|
* // -> [[], '0', ['1']]
|
|
574
585
|
* ```
|
|
586
|
+
* @category Movement
|
|
575
587
|
*/
|
|
576
588
|
goBackward(): Checkpoints;
|
|
577
589
|
|
|
@@ -592,7 +604,7 @@ export interface Checkpoints {
|
|
|
592
604
|
* goes backward to the state of the Store before the change. It then goes
|
|
593
605
|
* forward again to restore the state with the changes.
|
|
594
606
|
*
|
|
595
|
-
* ```
|
|
607
|
+
* ```js
|
|
596
608
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
597
609
|
*
|
|
598
610
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -622,7 +634,7 @@ export interface Checkpoints {
|
|
|
622
634
|
* change, the redo stack disappears, and then the attempt to forward again
|
|
623
635
|
* has no effect.
|
|
624
636
|
*
|
|
625
|
-
* ```
|
|
637
|
+
* ```js
|
|
626
638
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
627
639
|
*
|
|
628
640
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -651,6 +663,7 @@ export interface Checkpoints {
|
|
|
651
663
|
* // -> [['0'], undefined, []]
|
|
652
664
|
* // The original change cannot be redone.
|
|
653
665
|
* ```
|
|
666
|
+
* @category Movement
|
|
654
667
|
*/
|
|
655
668
|
goForward(): Checkpoints;
|
|
656
669
|
|
|
@@ -668,7 +681,7 @@ export interface Checkpoints {
|
|
|
668
681
|
* then goes forward again one change, also using the goTo method. Finally it
|
|
669
682
|
* tries to go to a checkpoint that does not exist.
|
|
670
683
|
*
|
|
671
|
-
* ```
|
|
684
|
+
* ```js
|
|
672
685
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
673
686
|
*
|
|
674
687
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -700,6 +713,7 @@ export interface Checkpoints {
|
|
|
700
713
|
* console.log(checkpoints.getCheckpointIds());
|
|
701
714
|
* // -> [['0'], '1', ['2']]
|
|
702
715
|
* ```
|
|
716
|
+
* @category Movement
|
|
703
717
|
*/
|
|
704
718
|
goTo(checkpointId: Id): Checkpoints;
|
|
705
719
|
|
|
@@ -724,7 +738,7 @@ export interface Checkpoints {
|
|
|
724
738
|
* This example creates a Store, a Checkpoints object, adds a listener, makes
|
|
725
739
|
* a change and then clears the checkpoints.
|
|
726
740
|
*
|
|
727
|
-
* ```
|
|
741
|
+
* ```js
|
|
728
742
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
729
743
|
*
|
|
730
744
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -773,7 +787,7 @@ export interface Checkpoints {
|
|
|
773
787
|
* CellListener with the underlying Store), and then destroys it again,
|
|
774
788
|
* removing the listener.
|
|
775
789
|
*
|
|
776
|
-
* ```
|
|
790
|
+
* ```js
|
|
777
791
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
778
792
|
*
|
|
779
793
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -807,7 +821,7 @@ export interface Checkpoints {
|
|
|
807
821
|
* @example
|
|
808
822
|
* This example gets the listener statistics of a Checkpoints object.
|
|
809
823
|
*
|
|
810
|
-
* ```
|
|
824
|
+
* ```js
|
|
811
825
|
* const store = createStore();
|
|
812
826
|
* const checkpoints = createCheckpoints(store);
|
|
813
827
|
* checkpoints.addCheckpointIdsListener(() => {
|
|
@@ -840,7 +854,7 @@ export interface Checkpoints {
|
|
|
840
854
|
* @example
|
|
841
855
|
* This example creates a Checkpoints object.
|
|
842
856
|
*
|
|
843
|
-
* ```
|
|
857
|
+
* ```js
|
|
844
858
|
* const store = createStore();
|
|
845
859
|
* const checkpoints = createCheckpoints(store);
|
|
846
860
|
* console.log(checkpoints.getCheckpointIds());
|
|
@@ -850,12 +864,13 @@ export interface Checkpoints {
|
|
|
850
864
|
* This example creates a Checkpoints object, and calls the method a second
|
|
851
865
|
* time for the same Store to return the same object.
|
|
852
866
|
*
|
|
853
|
-
* ```
|
|
867
|
+
* ```js
|
|
854
868
|
* const store = createStore();
|
|
855
869
|
* const checkpoints1 = createCheckpoints(store);
|
|
856
870
|
* const checkpoints2 = createCheckpoints(store);
|
|
857
871
|
* console.log(checkpoints1 === checkpoints2);
|
|
858
872
|
* // -> true
|
|
859
873
|
* ```
|
|
874
|
+
* @category Creation
|
|
860
875
|
*/
|
|
861
876
|
export function createCheckpoints(store: Store): Checkpoints;
|
package/lib/checkpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,s=e=>0==n(e),o=e=>e.slice(1),r=e=>null==e,l=(e,t,n)=>r(e)?n?.():t(e),c=(e,t)=>e?.has(t)??!1,i=e=>r(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),a=(e,t)=>e?.delete(t),p=e=>new Map(e),u=(e,t)=>e?.get(t),h=(e,t,n)=>r(n)?(a(e,t),e):e?.set(t,n),g=(e,t,n,s)=>(c(e,t)||(s?.(n),e.set(t,n)),u(e,t)),C=e=>new Set(e),k=(e,t,r)=>n(r)<2?((e,t)=>e?.add(t))(s(r)?e:g(e,r[0],C()),t):k(g(e,r[0],p()),t,o(r)),f=e=>{const n=(r,c,...i)=>l(r,(r=>s(i)?e(r,c):t([i[0],null],(e=>n(u(r,e),c,...o(i))))));return n},L=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((o=>{let w,v,S,z=100,E=p(),I=1;const M=C(),b=p(),[j,x,y]=(e=>{let s,o=0;const c=[],i=p();return[(t,n,r=[])=>{s
|
|
1
|
+
const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,s=e=>0==n(e),o=e=>e.slice(1),r=e=>null==e,l=(e,t,n)=>r(e)?n?.():t(e),c=(e,t)=>e?.has(t)??!1,i=e=>r(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),a=(e,t)=>e?.delete(t),p=e=>new Map(e),u=(e,t)=>e?.get(t),h=(e,t,n)=>r(n)?(a(e,t),e):e?.set(t,n),g=(e,t,n,s)=>(c(e,t)||(s?.(n),e.set(t,n)),u(e,t)),C=e=>new Set(e),k=(e,t,r)=>n(r)<2?((e,t)=>e?.add(t))(s(r)?e:g(e,r[0],C()),t):k(g(e,r[0],p()),t,o(r)),f=e=>{const n=(r,c,...i)=>l(r,(r=>s(i)?e(r,c):t([i[0],null],(e=>n(u(r,e),c,...o(i))))));return n},L=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((o=>{let w,v,S,z=100,E=p(),I=1;const M=C(),b=p(),[j,x,y]=(e=>{let s,o=0;const c=[],i=p();return[(t,n,r=[])=>{s??=e();const l=c.pop()??""+o++;return h(i,l,[t,n,r]),k(n,l,r),l},(e,t=[],...n)=>f(d)(e,(e=>l(u(i,e),(([e])=>e(s,...t,...n)))),...t),e=>l(u(i,e),(([,t,s])=>(f(a)(t,e,...s),h(i,e),n(c)<1e3&&c.push(e),s)),(()=>[])),(e,o,c)=>l(u(i,e),(([e,,l])=>{const i=(...d)=>{const a=n(d);a==n(l)?e(s,...d,...c(d)):r(l[a])?t(o[a](...d),(e=>i(...d,e))):i(...d,l[a])};i()}))]})((()=>Q)),B=p(),F=p(),O=[],T=[],W=(e,t)=>{I=0,o.transaction((()=>d(u(B,t),((t,n)=>d(t,((t,s)=>d(t,((t,l)=>r(t[e])?o.delCell(n,s,l,!0):o.setCell(n,s,l,t[e]))))))))),I=1},m=e=>{h(B,e),h(F,e),x(b,[e])},q=(e,s)=>t(((e,t)=>e.splice(0,t))(e,s??n(e)),m),A=()=>q(O,n(O)-z),D=o.addCellListener(null,null,null,((e,t,n,s,o,r)=>{if(I){l(w,(()=>{O.push(w),A(),q(T),w=void 0,S=1}));const e=g(E,t,p()),c=g(e,n,p()),d=g(c,s,[void 0,void 0],(e=>e[0]=r));d[1]=o,d[0]===d[1]&&i(h(c,s))&&i(h(e,n))&&i(h(E,t))&&(w=O.pop(),S=1),K()}})),G=(e="")=>(r(w)&&(w=""+v++,h(B,w,E),P(w,e),E=p(),S=1),w),H=()=>{s(O)||(T.unshift(G()),W(0,w),w=O.pop(),S=1)},J=()=>{s(T)||(O.push(w),w=T.shift(),W(1,w),S=1)},K=()=>{S&&(x(M),S=0)},N=e=>{const t=G(e);return K(),t},P=(e,t)=>(c(B,e)&&u(F,e)!==t&&(h(F,e,t),x(b,[e])),Q),Q={setSize:e=>(z=e,A(),Q),addCheckpoint:N,setCheckpoint:P,getStore:()=>o,getCheckpointIds:()=>[[...O],w,[...T]],getCheckpoint:e=>u(F,e),goBackward:()=>(H(),K(),Q),goForward:()=>(J(),K(),Q),goTo:t=>{const n=e(O,t)?H:e(T,t)?J:null;for(;!r(n)&&t!=w;)n();return K(),Q},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,t)=>j(t,b,[e]),delListener:e=>(y(e),Q),clear:()=>(q(O),q(T),r(w)||m(w),w=void 0,v=0,N(),Q),destroy:()=>{o.delListener(D)},getListenerStats:()=>({})};return L(Q.clear())}));export{w as createCheckpoints};
|
package/lib/checkpoints.js.gz
CHANGED
|
Binary file
|
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,7 @@ export type CheckpointsListenerStats = {
|
|
|
132
142
|
* checkpoints.delListener(listenerId);
|
|
133
143
|
* checkpoints.destroy();
|
|
134
144
|
* ```
|
|
145
|
+
* @category Checkpoints
|
|
135
146
|
*/
|
|
136
147
|
export interface Checkpoints {
|
|
137
148
|
/**
|
|
@@ -151,7 +162,7 @@ export interface Checkpoints {
|
|
|
151
162
|
* of the Checkpoints object dramatically and then creates more than that
|
|
152
163
|
* number of checkpoints to demonstrate the oldest being pruned.
|
|
153
164
|
*
|
|
154
|
-
* ```
|
|
165
|
+
* ```js
|
|
155
166
|
* const store = createStore().setTables({pets: {fido: {views: 0}}});
|
|
156
167
|
*
|
|
157
168
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -196,7 +207,7 @@ export interface Checkpoints {
|
|
|
196
207
|
* This example creates a Store, adds a Checkpoints object, and adds two
|
|
197
208
|
* checkpoints, one with a label.
|
|
198
209
|
*
|
|
199
|
-
* ```
|
|
210
|
+
* ```js
|
|
200
211
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
201
212
|
*
|
|
202
213
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -245,7 +256,7 @@ export interface Checkpoints {
|
|
|
245
256
|
* This example creates a Store, adds a Checkpoints object, and sets two
|
|
246
257
|
* checkpoints, one with a label, which are both then re-labelled.
|
|
247
258
|
*
|
|
248
|
-
* ```
|
|
259
|
+
* ```js
|
|
249
260
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
250
261
|
*
|
|
251
262
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -288,7 +299,7 @@ export interface Checkpoints {
|
|
|
288
299
|
* and then gets its reference in order to update its data and set a
|
|
289
300
|
* checkpoint.
|
|
290
301
|
*
|
|
291
|
-
* ```
|
|
302
|
+
* ```js
|
|
292
303
|
* const checkpoints = createCheckpoints(createStore());
|
|
293
304
|
* checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
|
|
294
305
|
* checkpoints.addCheckpoint();
|
|
@@ -315,7 +326,7 @@ export interface Checkpoints {
|
|
|
315
326
|
* This example creates a Store, adds a Checkpoints object, and then gets the
|
|
316
327
|
* Ids of the checkpoints as it sets them and moves around the stack.
|
|
317
328
|
*
|
|
318
|
-
* ```
|
|
329
|
+
* ```js
|
|
319
330
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
320
331
|
*
|
|
321
332
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -354,7 +365,7 @@ export interface Checkpoints {
|
|
|
354
365
|
* This example creates a Store, adds a Checkpoints object, and sets a
|
|
355
366
|
* checkpoint with a label, before retrieving it again.
|
|
356
367
|
*
|
|
357
|
-
* ```
|
|
368
|
+
* ```js
|
|
358
369
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
359
370
|
*
|
|
360
371
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -370,7 +381,7 @@ export interface Checkpoints {
|
|
|
370
381
|
* checkpoint without a label, setting it subsequently. A non-existent
|
|
371
382
|
* checkpoint return an `undefined` label.
|
|
372
383
|
*
|
|
373
|
-
* ```
|
|
384
|
+
* ```js
|
|
374
385
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
375
386
|
*
|
|
376
387
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -405,7 +416,7 @@ export interface Checkpoints {
|
|
|
405
416
|
* This example creates a Store, a Checkpoints object, and then registers a
|
|
406
417
|
* listener that responds to any changes to the checkpoints.
|
|
407
418
|
*
|
|
408
|
-
* ```
|
|
419
|
+
* ```js
|
|
409
420
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
410
421
|
*
|
|
411
422
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -463,7 +474,7 @@ export interface Checkpoints {
|
|
|
463
474
|
* listener that responds to any changes to a specific checkpoint label,
|
|
464
475
|
* including when the checkpoint no longer exists.
|
|
465
476
|
*
|
|
466
|
-
* ```
|
|
477
|
+
* ```js
|
|
467
478
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
468
479
|
*
|
|
469
480
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -516,7 +527,7 @@ export interface Checkpoints {
|
|
|
516
527
|
* This example creates a Store, a Checkpoints object, registers a listener,
|
|
517
528
|
* and then removes it.
|
|
518
529
|
*
|
|
519
|
-
* ```
|
|
530
|
+
* ```js
|
|
520
531
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
521
532
|
*
|
|
522
533
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -554,7 +565,7 @@ export interface Checkpoints {
|
|
|
554
565
|
* This example creates a Store, a Checkpoints object, makes a change and then
|
|
555
566
|
* goes backward to the state of the Store before the change.
|
|
556
567
|
*
|
|
557
|
-
* ```
|
|
568
|
+
* ```js
|
|
558
569
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
559
570
|
*
|
|
560
571
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -572,6 +583,7 @@ export interface Checkpoints {
|
|
|
572
583
|
* console.log(checkpoints.getCheckpointIds());
|
|
573
584
|
* // -> [[], '0', ['1']]
|
|
574
585
|
* ```
|
|
586
|
+
* @category Movement
|
|
575
587
|
*/
|
|
576
588
|
goBackward(): Checkpoints;
|
|
577
589
|
|
|
@@ -592,7 +604,7 @@ export interface Checkpoints {
|
|
|
592
604
|
* goes backward to the state of the Store before the change. It then goes
|
|
593
605
|
* forward again to restore the state with the changes.
|
|
594
606
|
*
|
|
595
|
-
* ```
|
|
607
|
+
* ```js
|
|
596
608
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
597
609
|
*
|
|
598
610
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -622,7 +634,7 @@ export interface Checkpoints {
|
|
|
622
634
|
* change, the redo stack disappears, and then the attempt to forward again
|
|
623
635
|
* has no effect.
|
|
624
636
|
*
|
|
625
|
-
* ```
|
|
637
|
+
* ```js
|
|
626
638
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
627
639
|
*
|
|
628
640
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -651,6 +663,7 @@ export interface Checkpoints {
|
|
|
651
663
|
* // -> [['0'], undefined, []]
|
|
652
664
|
* // The original change cannot be redone.
|
|
653
665
|
* ```
|
|
666
|
+
* @category Movement
|
|
654
667
|
*/
|
|
655
668
|
goForward(): Checkpoints;
|
|
656
669
|
|
|
@@ -668,7 +681,7 @@ export interface Checkpoints {
|
|
|
668
681
|
* then goes forward again one change, also using the goTo method. Finally it
|
|
669
682
|
* tries to go to a checkpoint that does not exist.
|
|
670
683
|
*
|
|
671
|
-
* ```
|
|
684
|
+
* ```js
|
|
672
685
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
673
686
|
*
|
|
674
687
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -700,6 +713,7 @@ export interface Checkpoints {
|
|
|
700
713
|
* console.log(checkpoints.getCheckpointIds());
|
|
701
714
|
* // -> [['0'], '1', ['2']]
|
|
702
715
|
* ```
|
|
716
|
+
* @category Movement
|
|
703
717
|
*/
|
|
704
718
|
goTo(checkpointId: Id): Checkpoints;
|
|
705
719
|
|
|
@@ -724,7 +738,7 @@ export interface Checkpoints {
|
|
|
724
738
|
* This example creates a Store, a Checkpoints object, adds a listener, makes
|
|
725
739
|
* a change and then clears the checkpoints.
|
|
726
740
|
*
|
|
727
|
-
* ```
|
|
741
|
+
* ```js
|
|
728
742
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
729
743
|
*
|
|
730
744
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -773,7 +787,7 @@ export interface Checkpoints {
|
|
|
773
787
|
* CellListener with the underlying Store), and then destroys it again,
|
|
774
788
|
* removing the listener.
|
|
775
789
|
*
|
|
776
|
-
* ```
|
|
790
|
+
* ```js
|
|
777
791
|
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
778
792
|
*
|
|
779
793
|
* const checkpoints = createCheckpoints(store);
|
|
@@ -807,7 +821,7 @@ export interface Checkpoints {
|
|
|
807
821
|
* @example
|
|
808
822
|
* This example gets the listener statistics of a Checkpoints object.
|
|
809
823
|
*
|
|
810
|
-
* ```
|
|
824
|
+
* ```js
|
|
811
825
|
* const store = createStore();
|
|
812
826
|
* const checkpoints = createCheckpoints(store);
|
|
813
827
|
* checkpoints.addCheckpointIdsListener(() => {
|
|
@@ -840,7 +854,7 @@ export interface Checkpoints {
|
|
|
840
854
|
* @example
|
|
841
855
|
* This example creates a Checkpoints object.
|
|
842
856
|
*
|
|
843
|
-
* ```
|
|
857
|
+
* ```js
|
|
844
858
|
* const store = createStore();
|
|
845
859
|
* const checkpoints = createCheckpoints(store);
|
|
846
860
|
* console.log(checkpoints.getCheckpointIds());
|
|
@@ -850,12 +864,13 @@ export interface Checkpoints {
|
|
|
850
864
|
* This example creates a Checkpoints object, and calls the method a second
|
|
851
865
|
* time for the same Store to return the same object.
|
|
852
866
|
*
|
|
853
|
-
* ```
|
|
867
|
+
* ```js
|
|
854
868
|
* const store = createStore();
|
|
855
869
|
* const checkpoints1 = createCheckpoints(store);
|
|
856
870
|
* const checkpoints2 = createCheckpoints(store);
|
|
857
871
|
* console.log(checkpoints1 === checkpoints2);
|
|
858
872
|
* // -> true
|
|
859
873
|
* ```
|
|
874
|
+
* @category Creation
|
|
860
875
|
*/
|
|
861
876
|
export function createCheckpoints(store: Store): Checkpoints;
|
package/lib/debug/checkpoints.js
CHANGED
|
@@ -73,7 +73,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
73
73
|
const listenerPool = [];
|
|
74
74
|
const allListeners = mapNew();
|
|
75
75
|
const addListener = (listener, deepSet, idOrNulls = []) => {
|
|
76
|
-
thing
|
|
76
|
+
thing ??= getThing();
|
|
77
77
|
const id = listenerPool.pop() ?? '' + nextId++;
|
|
78
78
|
mapSet(allListeners, id, [listener, deepSet, idOrNulls]);
|
|
79
79
|
addDeepSet(deepSet, id, idOrNulls);
|
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;
|