tinybase 0.9.2 → 0.9.3
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/debug/checkpoints.d.ts +35 -20
- package/lib/debug/indexes.d.ts +35 -21
- package/lib/debug/metrics.d.ts +43 -18
- package/lib/debug/persisters.d.ts +197 -14
- package/lib/debug/relationships.d.ts +45 -22
- package/lib/debug/store.d.ts +171 -92
- package/lib/debug/tinybase.d.ts +1 -2
- package/lib/debug/ui-react.d.ts +242 -161
- package/lib/debug/ui-react.js +16 -13
- package/lib/indexes.d.ts +35 -21
- package/lib/metrics.d.ts +43 -18
- package/lib/persisters.d.ts +197 -14
- package/lib/relationships.d.ts +45 -22
- package/lib/store.d.ts +171 -92
- package/lib/tinybase.d.ts +1 -2
- package/lib/ui-react.d.ts +242 -161
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +4 -4
- package/readme.md +13 -13
package/lib/persisters.d.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* - The createLocalPersister function returns a Persister that uses the
|
|
12
12
|
* browser's local storage.
|
|
13
13
|
* - The createRemotePersister function returns a Persister that uses a remote
|
|
14
|
-
*
|
|
14
|
+
* server.
|
|
15
15
|
* - The createFilePersister function returns a Persister that uses a local file
|
|
16
|
-
* (in an appropriate environment)
|
|
16
|
+
* (in an appropriate environment).
|
|
17
17
|
*
|
|
18
18
|
* Since persistence requirements can be different for every app, the
|
|
19
19
|
* createCustomPersister function can also be used to easily create a fully
|
|
@@ -89,7 +89,7 @@ export type PersisterStats = {
|
|
|
89
89
|
* a JSON string, changes the persisted data, updates the Store from it, and
|
|
90
90
|
* finally destroys the Persister again.
|
|
91
91
|
*
|
|
92
|
-
* ```
|
|
92
|
+
* ```js
|
|
93
93
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
94
94
|
* const persister = createSessionPersister(store, 'pets');
|
|
95
95
|
*
|
|
@@ -110,7 +110,7 @@ export type PersisterStats = {
|
|
|
110
110
|
* browser's session storage as a JSON string. Changes to the Store data, or the
|
|
111
111
|
* persisted data (implicitly firing a StorageEvent), are reflected accordingly.
|
|
112
112
|
*
|
|
113
|
-
* ```
|
|
113
|
+
* ```js
|
|
114
114
|
* const store = createStore();
|
|
115
115
|
* const persister = createSessionPersister(store, 'pets');
|
|
116
116
|
*
|
|
@@ -133,6 +133,7 @@ export type PersisterStats = {
|
|
|
133
133
|
* persister.destroy();
|
|
134
134
|
* sessionStorage.clear();
|
|
135
135
|
* ```
|
|
136
|
+
* @category Persister
|
|
136
137
|
*/
|
|
137
138
|
export interface Persister {
|
|
138
139
|
/**
|
|
@@ -158,7 +159,7 @@ export interface Persister {
|
|
|
158
159
|
* browser's session storage, which for the purposes of this example has been
|
|
159
160
|
* previously populated.
|
|
160
161
|
*
|
|
161
|
-
* ```
|
|
162
|
+
* ```js
|
|
162
163
|
* sessionStorage.setItem('pets', '{"pets":{"fido":{"species":"dog"}}}');
|
|
163
164
|
*
|
|
164
165
|
* const store = createStore();
|
|
@@ -176,7 +177,7 @@ export interface Persister {
|
|
|
176
177
|
* parameter is used. The second time the load method is called, data has
|
|
177
178
|
* previously been persisted and instead, that is loaded.
|
|
178
179
|
*
|
|
179
|
-
* ```
|
|
180
|
+
* ```js
|
|
180
181
|
* const store = createStore();
|
|
181
182
|
* const persister = createSessionPersister(store, 'pets');
|
|
182
183
|
*
|
|
@@ -226,7 +227,7 @@ export interface Persister {
|
|
|
226
227
|
* reflected in the Store (in this case through detection of StorageEvents
|
|
227
228
|
* from session storage changes made in another browser tab).
|
|
228
229
|
*
|
|
229
|
-
* ```
|
|
230
|
+
* ```js
|
|
230
231
|
* const store = createStore();
|
|
231
232
|
* const persister = createSessionPersister(store, 'pets');
|
|
232
233
|
*
|
|
@@ -261,7 +262,7 @@ export interface Persister {
|
|
|
261
262
|
* into it from the browser's session storage. Once the automatic loading is
|
|
262
263
|
* stopped, subsequent changes are not reflected in the Store.
|
|
263
264
|
*
|
|
264
|
-
* ```
|
|
265
|
+
* ```js
|
|
265
266
|
* const store = createStore();
|
|
266
267
|
* const persister = createSessionPersister(store, 'pets');
|
|
267
268
|
* await persister.startAutoLoad();
|
|
@@ -303,7 +304,7 @@ export interface Persister {
|
|
|
303
304
|
* This example creates a Store with some data, and saves into the browser's
|
|
304
305
|
* session storage.
|
|
305
306
|
*
|
|
306
|
-
* ```
|
|
307
|
+
* ```js
|
|
307
308
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
308
309
|
* const persister = createSessionPersister(store, 'pets');
|
|
309
310
|
*
|
|
@@ -314,6 +315,7 @@ export interface Persister {
|
|
|
314
315
|
* persister.destroy();
|
|
315
316
|
* sessionStorage.clear();
|
|
316
317
|
* ```
|
|
318
|
+
* @category Save
|
|
317
319
|
*/
|
|
318
320
|
save(): Promise<Persister>;
|
|
319
321
|
|
|
@@ -336,7 +338,7 @@ export interface Persister {
|
|
|
336
338
|
* session storage. Subsequent changes to the Store are then automatically
|
|
337
339
|
* saved to the underlying storage.
|
|
338
340
|
*
|
|
339
|
-
* ```
|
|
341
|
+
* ```js
|
|
340
342
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
341
343
|
* const persister = createSessionPersister(store, 'pets');
|
|
342
344
|
*
|
|
@@ -351,6 +353,7 @@ export interface Persister {
|
|
|
351
353
|
*
|
|
352
354
|
* sessionStorage.clear();
|
|
353
355
|
* ```
|
|
356
|
+
* @category Save
|
|
354
357
|
*/
|
|
355
358
|
startAutoSave(): Promise<Persister>;
|
|
356
359
|
|
|
@@ -368,7 +371,7 @@ export interface Persister {
|
|
|
368
371
|
* saved to the underlying storage. Once the automatic saving is
|
|
369
372
|
* stopped, subsequent changes are not reflected.
|
|
370
373
|
*
|
|
371
|
-
* ```
|
|
374
|
+
* ```js
|
|
372
375
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
373
376
|
* const persister = createSessionPersister(store, 'pets');
|
|
374
377
|
* await persister.startAutoSave();
|
|
@@ -401,7 +404,7 @@ export interface Persister {
|
|
|
401
404
|
* This example creates a Persister object against a newly-created Store and
|
|
402
405
|
* then gets its reference in order to update its data.
|
|
403
406
|
*
|
|
404
|
-
* ```
|
|
407
|
+
* ```js
|
|
405
408
|
* const persister = createSessionPersister(createStore(), 'pets');
|
|
406
409
|
* await persister.startAutoSave();
|
|
407
410
|
*
|
|
@@ -430,7 +433,7 @@ export interface Persister {
|
|
|
430
433
|
* registers a TablesListener with the underlying Store), and then destroys it
|
|
431
434
|
* again, removing the listener.
|
|
432
435
|
*
|
|
433
|
-
* ```
|
|
436
|
+
* ```js
|
|
434
437
|
* const store = createStore();
|
|
435
438
|
* const persister = createSessionPersister(store, 'pets');
|
|
436
439
|
* await persister.startAutoSave();
|
|
@@ -468,7 +471,7 @@ export interface Persister {
|
|
|
468
471
|
* starts - so those numbers are included in addition to the loads and saves
|
|
469
472
|
* invoked by changes to the Store and to the underlying storage.
|
|
470
473
|
*
|
|
471
|
-
* ```
|
|
474
|
+
* ```js
|
|
472
475
|
* const store = createStore();
|
|
473
476
|
* const persister = createSessionPersister(store, 'pets');
|
|
474
477
|
*
|
|
@@ -493,16 +496,114 @@ export interface Persister {
|
|
|
493
496
|
getStats(): PersisterStats;
|
|
494
497
|
}
|
|
495
498
|
|
|
499
|
+
/**
|
|
500
|
+
* The createSessionPersister function creates an Persister object that can
|
|
501
|
+
* persist the Store to the browser's session storage.
|
|
502
|
+
*
|
|
503
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
504
|
+
* `storageName` parameter which is unique to your application. This is the key
|
|
505
|
+
* that the browser uses to identify the storage location.
|
|
506
|
+
*
|
|
507
|
+
* @param store The Store to persist.
|
|
508
|
+
* @param storageName The unique key to identify the storage location.
|
|
509
|
+
* @returns A reference to the new Persister object.
|
|
510
|
+
* @example
|
|
511
|
+
* This example creates a Persister object and persists the Store to the
|
|
512
|
+
* browser's session storage.
|
|
513
|
+
*
|
|
514
|
+
* ```js
|
|
515
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
516
|
+
* const persister = createSessionPersister(store, 'pets');
|
|
517
|
+
*
|
|
518
|
+
* await persister.save();
|
|
519
|
+
* console.log(sessionStorage.getItem('pets'));
|
|
520
|
+
* // -> '{"pets":{"fido":{"species":"dog"}}}'
|
|
521
|
+
*
|
|
522
|
+
* persister.destroy();
|
|
523
|
+
* sessionStorage.clear();
|
|
524
|
+
* ```
|
|
525
|
+
* @category Creation
|
|
526
|
+
*/
|
|
496
527
|
export function createSessionPersister(
|
|
497
528
|
store: Store,
|
|
498
529
|
storageName: string,
|
|
499
530
|
): Persister;
|
|
500
531
|
|
|
532
|
+
/**
|
|
533
|
+
* The createLocalPersister function creates an Persister object that can
|
|
534
|
+
* persist the Store to the browser's local storage.
|
|
535
|
+
*
|
|
536
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
537
|
+
* `storageName` parameter which is unique to your application. This is the key
|
|
538
|
+
* that the browser uses to identify the storage location.
|
|
539
|
+
*
|
|
540
|
+
* @param store The Store to persist.
|
|
541
|
+
* @param storageName The unique key to identify the storage location.
|
|
542
|
+
* @returns A reference to the new Persister object.
|
|
543
|
+
* @example
|
|
544
|
+
* This example creates a Persister object and persists the Store to the
|
|
545
|
+
* browser's local storage.
|
|
546
|
+
*
|
|
547
|
+
* ```js
|
|
548
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
549
|
+
* const persister = createLocalPersister(store, 'pets');
|
|
550
|
+
*
|
|
551
|
+
* await persister.save();
|
|
552
|
+
* console.log(localStorage.getItem('pets'));
|
|
553
|
+
* // -> '{"pets":{"fido":{"species":"dog"}}}'
|
|
554
|
+
*
|
|
555
|
+
* persister.destroy();
|
|
556
|
+
* localStorage.clear();
|
|
557
|
+
* ```
|
|
558
|
+
* @category Creation
|
|
559
|
+
*/
|
|
501
560
|
export function createLocalPersister(
|
|
502
561
|
store: Store,
|
|
503
562
|
storageName: string,
|
|
504
563
|
): Persister;
|
|
505
564
|
|
|
565
|
+
/**
|
|
566
|
+
* The createRemotePersister function creates an Persister object that can
|
|
567
|
+
* persist the Store to a remote server.
|
|
568
|
+
*
|
|
569
|
+
* As well as providing a reference to the Store to persist, you must provide
|
|
570
|
+
* `loadUrl` and `saveUrl` parameters. These identify the endpoints of the
|
|
571
|
+
* server that support the `GET` method (to fetch the Store JSON to load) and
|
|
572
|
+
* the `POST` method (to send the Store JSON to save) respectively.
|
|
573
|
+
*
|
|
574
|
+
* For when you choose to enable automatic loading for the Persister (with the
|
|
575
|
+
* startAutoLoad method), it will poll the loadUrl for changes. The
|
|
576
|
+
* `autoLoadIntervalSeconds` method is used to indicate how often to do this.
|
|
577
|
+
*
|
|
578
|
+
* @param store The Store to persist.
|
|
579
|
+
* @param loadUrl The endpoint that supports a `GET` method to load JSON.
|
|
580
|
+
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
|
|
581
|
+
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
|
|
582
|
+
* automatically loading changes from the server.
|
|
583
|
+
* @returns A reference to the new Persister object.
|
|
584
|
+
* @example
|
|
585
|
+
* This example creates a Persister object and persists the Store to a remote
|
|
586
|
+
* server.
|
|
587
|
+
*
|
|
588
|
+
* ```js yolo
|
|
589
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
590
|
+
* const persister = createRemotePersister(
|
|
591
|
+
* store,
|
|
592
|
+
* 'https://example.com/load',
|
|
593
|
+
* 'https://example.com/save',
|
|
594
|
+
* 5,
|
|
595
|
+
* );
|
|
596
|
+
*
|
|
597
|
+
* await persister.save();
|
|
598
|
+
* // Store JSON will be sent to server in a POST request.
|
|
599
|
+
*
|
|
600
|
+
* await persister.load();
|
|
601
|
+
* // Store JSON will be fetched from server with a GET request.
|
|
602
|
+
*
|
|
603
|
+
* persister.destroy();
|
|
604
|
+
* ```
|
|
605
|
+
* @category Creation
|
|
606
|
+
*/
|
|
506
607
|
export function createRemotePersister(
|
|
507
608
|
store: Store,
|
|
508
609
|
loadUrl: string,
|
|
@@ -510,8 +611,90 @@ export function createRemotePersister(
|
|
|
510
611
|
autoLoadIntervalSeconds: number,
|
|
511
612
|
): Persister;
|
|
512
613
|
|
|
614
|
+
/**
|
|
615
|
+
* The createFilePersister function creates an Persister object that can persist
|
|
616
|
+
* the Store to a local file (in an appropriate environment).
|
|
617
|
+
*
|
|
618
|
+
* As well as providing a reference to the Store to persist, you must provide
|
|
619
|
+
* `filePath` parameter which identifies the file to persist it to.
|
|
620
|
+
*
|
|
621
|
+
* @param store The Store to persist.
|
|
622
|
+
* @param filePath The location of the local file to persist the Store to.
|
|
623
|
+
* @returns A reference to the new Persister object.
|
|
624
|
+
* @example
|
|
625
|
+
* This example creates a Persister object and persists the Store to a local
|
|
626
|
+
* file.
|
|
627
|
+
*
|
|
628
|
+
* ```js yolo
|
|
629
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
630
|
+
* const persister = createFilePersister(store, '/app/persisted.json');
|
|
631
|
+
*
|
|
632
|
+
* await persister.save();
|
|
633
|
+
* // Store JSON will be saved to the file.
|
|
634
|
+
*
|
|
635
|
+
* await persister.load();
|
|
636
|
+
* // Store JSON will be loaded from the file.
|
|
637
|
+
*
|
|
638
|
+
* persister.destroy();
|
|
639
|
+
* ```
|
|
640
|
+
* @category Creation
|
|
641
|
+
*/
|
|
513
642
|
export function createFilePersister(store: Store, filePath: string): Persister;
|
|
514
643
|
|
|
644
|
+
/**
|
|
645
|
+
* The createCustomPersister function creates an Persister object that you can
|
|
646
|
+
* configure to persist the Store in any way you wish.
|
|
647
|
+
*
|
|
648
|
+
* As well as providing a reference to the Store to persist, you must provide
|
|
649
|
+
* functions that handle how to fetch, write, and listen to, the persistence
|
|
650
|
+
* layer.
|
|
651
|
+
*
|
|
652
|
+
* The other creation functions (such as the createSessionPersister function and
|
|
653
|
+
* createFilePersister function, for example) all use this under the covers. See
|
|
654
|
+
* those implementations for ideas on how to implement your own Persister types.
|
|
655
|
+
*
|
|
656
|
+
* @param store The Store to persist.
|
|
657
|
+
* @param getPersisted An asynchronous function which will fetch JSON from the
|
|
658
|
+
* persistence layer (or `null` or `undefined` if not present).
|
|
659
|
+
* @param setPersisted An asynchronous function which will send JSON to the
|
|
660
|
+
* persistence layer.
|
|
661
|
+
* @param startListeningToPersisted A function that will register a `didChange`
|
|
662
|
+
* listener on underlying changes to the persistence layer.
|
|
663
|
+
* @param stopListeningToPersisted A function that will unregister the listener
|
|
664
|
+
* from the underlying changes to the persistence layer.
|
|
665
|
+
* @returns A reference to the new Persister object.
|
|
666
|
+
* @example
|
|
667
|
+
* This example creates a Persister object and persists the Store to a local
|
|
668
|
+
* string called `storeJson` and would automatically load by polling for changes
|
|
669
|
+
* every second.
|
|
670
|
+
*
|
|
671
|
+
* ```js
|
|
672
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
673
|
+
* let storeJson;
|
|
674
|
+
* let interval;
|
|
675
|
+
*
|
|
676
|
+
* const persister = createCustomPersister(
|
|
677
|
+
* store,
|
|
678
|
+
* async () => storeJson,
|
|
679
|
+
* async (json) => (storeJson = json),
|
|
680
|
+
* (didChange) => (interval = setInterval(didChange, 1000)),
|
|
681
|
+
* () => clearInterval(interval),
|
|
682
|
+
* );
|
|
683
|
+
*
|
|
684
|
+
* await persister.save();
|
|
685
|
+
* console.log(storeJson);
|
|
686
|
+
* // -> '{"pets":{"fido":{"species":"dog"}}}'
|
|
687
|
+
*
|
|
688
|
+
* storeJson = '{"pets":{"fido":{"species":"dog","color":"brown"}}}';
|
|
689
|
+
* await persister.load();
|
|
690
|
+
*
|
|
691
|
+
* console.log(store.getTables());
|
|
692
|
+
* // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
|
|
693
|
+
*
|
|
694
|
+
* persister.destroy();
|
|
695
|
+
* ```
|
|
696
|
+
* @category Creation
|
|
697
|
+
*/
|
|
515
698
|
export function createCustomPersister(
|
|
516
699
|
store: Store,
|
|
517
700
|
getPersisted: () => Promise<string | null | undefined>,
|
package/lib/relationships.d.ts
CHANGED
|
@@ -50,6 +50,9 @@ export type Relationship = {
|
|
|
50
50
|
* object, the Id of the Relationship that changed, and the Id of the local Row
|
|
51
51
|
* whose remote Row Id changed.
|
|
52
52
|
*
|
|
53
|
+
* @param relationships A reference to the Relationships object that changed.
|
|
54
|
+
* @param relationshipId The Id of the Relationship that changed.
|
|
55
|
+
* @param localRowId The Id of the local Row whose remote Row Id changed.
|
|
53
56
|
* @category Listener
|
|
54
57
|
*/
|
|
55
58
|
export type RemoteRowIdListener = (
|
|
@@ -67,8 +70,11 @@ export type RemoteRowIdListener = (
|
|
|
67
70
|
*
|
|
68
71
|
* When called, a LocalRowIdsListener is given a reference to the Relationships
|
|
69
72
|
* object, the Id of the Relationship that changed, and the Id of the remote Row
|
|
70
|
-
* whose local Row
|
|
73
|
+
* whose local Row Ids changed.
|
|
71
74
|
*
|
|
75
|
+
* @param relationships A reference to the Relationships object that changed.
|
|
76
|
+
* @param relationshipId The Id of the Relationship that changed.
|
|
77
|
+
* @param remoteRowId The Id of the remote Row whose local Row Ids changed.
|
|
72
78
|
* @category Listener
|
|
73
79
|
*/
|
|
74
80
|
export type LocalRowIdsListener = (
|
|
@@ -88,6 +94,10 @@ export type LocalRowIdsListener = (
|
|
|
88
94
|
* object, the Id of the Relationship that changed, and the Id of the first Row
|
|
89
95
|
* of the the linked list whose members changed.
|
|
90
96
|
*
|
|
97
|
+
* @param relationships A reference to the Relationships object that changed.
|
|
98
|
+
* @param relationshipId The Id of the Relationship that changed.
|
|
99
|
+
* @param firstRowId The Id of the first Row of the the linked list whose
|
|
100
|
+
* members changed.
|
|
91
101
|
* @category Listener
|
|
92
102
|
*/
|
|
93
103
|
export type LinkedRowIdsListener = (
|
|
@@ -107,8 +117,19 @@ export type LinkedRowIdsListener = (
|
|
|
107
117
|
* @category Development
|
|
108
118
|
*/
|
|
109
119
|
export type RelationshipsListenerStats = {
|
|
120
|
+
/**
|
|
121
|
+
* The number of RemoteRowIdListeners registered with the Relationships
|
|
122
|
+
* object.
|
|
123
|
+
*/
|
|
110
124
|
remoteRowId?: number;
|
|
125
|
+
/**
|
|
126
|
+
* The number of LocalRowIdsListeners registered with the Relationships
|
|
127
|
+
* object.
|
|
128
|
+
*/
|
|
111
129
|
localRowIds?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The number of LinkedRowIds registered with the Relationships object.
|
|
132
|
+
*/
|
|
112
133
|
linkedRowIds?: number;
|
|
113
134
|
};
|
|
114
135
|
|
|
@@ -137,7 +158,7 @@ export type RelationshipsListenerStats = {
|
|
|
137
158
|
* creation, to adding definitions (both local/remote table and linked list),
|
|
138
159
|
* getting their contents, and then registering and removing listeners for them.
|
|
139
160
|
*
|
|
140
|
-
* ```
|
|
161
|
+
* ```js
|
|
141
162
|
* const store = createStore()
|
|
142
163
|
* .setTable('pets', {
|
|
143
164
|
* fido: {species: 'dog', next: 'felix'},
|
|
@@ -201,6 +222,7 @@ export type RelationshipsListenerStats = {
|
|
|
201
222
|
* relationships.delListener(listenerId2);
|
|
202
223
|
* relationships.destroy();
|
|
203
224
|
* ```
|
|
225
|
+
* @category Relationships
|
|
204
226
|
*/
|
|
205
227
|
export interface Relationships {
|
|
206
228
|
/**
|
|
@@ -239,7 +261,7 @@ export interface Relationships {
|
|
|
239
261
|
* a simple Relationship based on the values in the `species` Cell of the
|
|
240
262
|
* `pets` Table that relates a Row to another in the `species` Table.
|
|
241
263
|
*
|
|
242
|
-
* ```
|
|
264
|
+
* ```js
|
|
243
265
|
* const store = createStore()
|
|
244
266
|
* .setTable('pets', {
|
|
245
267
|
* fido: {species: 'dog'},
|
|
@@ -269,7 +291,7 @@ export interface Relationships {
|
|
|
269
291
|
* a linked list Relationship based on the values in the `next` Cell of the
|
|
270
292
|
* `pets` Table that relates a Row to another in the same Table.
|
|
271
293
|
*
|
|
272
|
-
* ```
|
|
294
|
+
* ```js
|
|
273
295
|
* const store = createStore().setTable('pets', {
|
|
274
296
|
* fido: {species: 'dog', next: 'felix'},
|
|
275
297
|
* felix: {species: 'cat', next: 'cujo'},
|
|
@@ -306,7 +328,7 @@ export interface Relationships {
|
|
|
306
328
|
* This example creates a Store, creates a Relationships object, defines a
|
|
307
329
|
* simple Relationship, and then removes it.
|
|
308
330
|
*
|
|
309
|
-
* ```
|
|
331
|
+
* ```js
|
|
310
332
|
* const store = createStore()
|
|
311
333
|
* .setTable('pets', {
|
|
312
334
|
* fido: {species: 'dog'},
|
|
@@ -345,7 +367,7 @@ export interface Relationships {
|
|
|
345
367
|
* This example creates a Relationships object against a newly-created Store
|
|
346
368
|
* and then gets its reference in order to update its data.
|
|
347
369
|
*
|
|
348
|
-
* ```
|
|
370
|
+
* ```js
|
|
349
371
|
* const relationships = createRelationships(createStore());
|
|
350
372
|
* relationships.setRelationshipDefinition(
|
|
351
373
|
* 'petSpecies',
|
|
@@ -370,7 +392,7 @@ export interface Relationships {
|
|
|
370
392
|
* This example creates a Relationships object with two definitions, and then
|
|
371
393
|
* gets the Ids of the definitions.
|
|
372
394
|
*
|
|
373
|
-
* ```
|
|
395
|
+
* ```js
|
|
374
396
|
* const relationships = createRelationships(createStore())
|
|
375
397
|
* .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
|
|
376
398
|
* .setRelationshipDefinition('petSequence', 'pets', 'pets', 'next');
|
|
@@ -395,7 +417,7 @@ export interface Relationships {
|
|
|
395
417
|
* definition, and then queries it (and a non-existent definition) to get the
|
|
396
418
|
* underlying local Table Id.
|
|
397
419
|
*
|
|
398
|
-
* ```
|
|
420
|
+
* ```js
|
|
399
421
|
* const relationships = createRelationships(createStore());
|
|
400
422
|
* relationships.setRelationshipDefinition(
|
|
401
423
|
* 'petSpecies',
|
|
@@ -427,7 +449,7 @@ export interface Relationships {
|
|
|
427
449
|
* definition, and then queries it (and a non-existent definition) to get the
|
|
428
450
|
* underlying remote Table Id.
|
|
429
451
|
*
|
|
430
|
-
* ```
|
|
452
|
+
* ```js
|
|
431
453
|
* const relationships = createRelationships(createStore());
|
|
432
454
|
* relationships.setRelationshipDefinition(
|
|
433
455
|
* 'petSpecies',
|
|
@@ -461,7 +483,7 @@ export interface Relationships {
|
|
|
461
483
|
* in the Relationship (and also the remote Row Ids for a local Row that does
|
|
462
484
|
* not exist, and for a Relationship that has not been defined).
|
|
463
485
|
*
|
|
464
|
-
* ```
|
|
486
|
+
* ```js
|
|
465
487
|
* const store = createStore()
|
|
466
488
|
* .setTable('pets', {
|
|
467
489
|
* fido: {species: 'dog'},
|
|
@@ -508,7 +530,7 @@ export interface Relationships {
|
|
|
508
530
|
* in the Relationship (and also the local Row Ids for a remote Row that does
|
|
509
531
|
* not exist, and for a Relationship that has not been defined).
|
|
510
532
|
*
|
|
511
|
-
* ```
|
|
533
|
+
* ```js
|
|
512
534
|
* const store = createStore()
|
|
513
535
|
* .setTable('pets', {
|
|
514
536
|
* fido: {species: 'dog'},
|
|
@@ -560,7 +582,7 @@ export interface Relationships {
|
|
|
560
582
|
* linked Row Ids in the Relationship (and also the linked Row Ids for a Row
|
|
561
583
|
* that does not exist, and for a Relationship that has not been defined).
|
|
562
584
|
*
|
|
563
|
-
* ```
|
|
585
|
+
* ```js
|
|
564
586
|
* const store = createStore().setTable('pets', {
|
|
565
587
|
* fido: {species: 'dog', next: 'felix'},
|
|
566
588
|
* felix: {species: 'cat', next: 'cujo'},
|
|
@@ -618,7 +640,7 @@ export interface Relationships {
|
|
|
618
640
|
* This example creates a Store, a Relationships object, and then registers a
|
|
619
641
|
* listener that responds to any changes to a specific local Row's remote Row.
|
|
620
642
|
*
|
|
621
|
-
* ```
|
|
643
|
+
* ```js
|
|
622
644
|
* const store = createStore()
|
|
623
645
|
* .setTable('pets', {
|
|
624
646
|
* fido: {species: 'dog'},
|
|
@@ -660,7 +682,7 @@ export interface Relationships {
|
|
|
660
682
|
* also illustrates how you can use the getStore method and the getRemoteRowId
|
|
661
683
|
* method to resolve the remote Row as a whole.
|
|
662
684
|
*
|
|
663
|
-
* ```
|
|
685
|
+
* ```js
|
|
664
686
|
* const store = createStore()
|
|
665
687
|
* .setTable('pets', {
|
|
666
688
|
* fido: {species: 'dog', color: 'brown'},
|
|
@@ -750,7 +772,7 @@ export interface Relationships {
|
|
|
750
772
|
* listener that responds to any changes to a specific remote Row's local Row
|
|
751
773
|
* objects.
|
|
752
774
|
*
|
|
753
|
-
* ```
|
|
775
|
+
* ```js
|
|
754
776
|
* const store = createStore()
|
|
755
777
|
* .setTable('pets', {
|
|
756
778
|
* fido: {species: 'dog'},
|
|
@@ -791,7 +813,7 @@ export interface Relationships {
|
|
|
791
813
|
* listener that responds to any changes to any remote Row's local Row
|
|
792
814
|
* objects.
|
|
793
815
|
*
|
|
794
|
-
* ```
|
|
816
|
+
* ```js
|
|
795
817
|
* const store = createStore()
|
|
796
818
|
* .setTable('pets', {
|
|
797
819
|
* fido: {species: 'dog', color: 'brown'},
|
|
@@ -877,7 +899,7 @@ export interface Relationships {
|
|
|
877
899
|
* listener that responds to any changes to a specific first Row's linked Row
|
|
878
900
|
* objects.
|
|
879
901
|
*
|
|
880
|
-
* ```
|
|
902
|
+
* ```js
|
|
881
903
|
* const store = createStore().setTable('pets', {
|
|
882
904
|
* fido: {species: 'dog', next: 'felix'},
|
|
883
905
|
* felix: {species: 'cat', next: 'cujo'},
|
|
@@ -930,7 +952,7 @@ export interface Relationships {
|
|
|
930
952
|
* This example creates a Store, a Relationships object, registers a listener,
|
|
931
953
|
* and then removes it.
|
|
932
954
|
*
|
|
933
|
-
* ```
|
|
955
|
+
* ```js
|
|
934
956
|
* const store = createStore()
|
|
935
957
|
* .setTable('pets', {
|
|
936
958
|
* fido: {species: 'dog'},
|
|
@@ -984,7 +1006,7 @@ export interface Relationships {
|
|
|
984
1006
|
* definition (that registers a RowListener with the underlying Store),
|
|
985
1007
|
* and then destroys it again, removing the listener.
|
|
986
1008
|
*
|
|
987
|
-
* ```
|
|
1009
|
+
* ```js
|
|
988
1010
|
* const store = createStore()
|
|
989
1011
|
* .setTable('pets', {
|
|
990
1012
|
* fido: {species: 'dog'},
|
|
@@ -1034,7 +1056,7 @@ export interface Relationships {
|
|
|
1034
1056
|
* @example
|
|
1035
1057
|
* This example gets the listener statistics of a Relationships object.
|
|
1036
1058
|
*
|
|
1037
|
-
* ```
|
|
1059
|
+
* ```js
|
|
1038
1060
|
* const store = createStore();
|
|
1039
1061
|
* const relationships = createRelationships(store);
|
|
1040
1062
|
* relationships.addRemoteRowIdListener(null, null, () => {
|
|
@@ -1070,7 +1092,7 @@ export interface Relationships {
|
|
|
1070
1092
|
* @example
|
|
1071
1093
|
* This example creates an Relationships object.
|
|
1072
1094
|
*
|
|
1073
|
-
* ```
|
|
1095
|
+
* ```js
|
|
1074
1096
|
* const store = createStore();
|
|
1075
1097
|
* const relationships = createRelationships(store);
|
|
1076
1098
|
* console.log(relationships.getRelationshipIds());
|
|
@@ -1080,12 +1102,13 @@ export interface Relationships {
|
|
|
1080
1102
|
* This example creates a Relationships object, and calls the method a second
|
|
1081
1103
|
* time for the same Store to return the same object.
|
|
1082
1104
|
*
|
|
1083
|
-
* ```
|
|
1105
|
+
* ```js
|
|
1084
1106
|
* const store = createStore();
|
|
1085
1107
|
* const relationships1 = createRelationships(store);
|
|
1086
1108
|
* const relationships2 = createRelationships(store);
|
|
1087
1109
|
* console.log(relationships1 === relationships2);
|
|
1088
1110
|
* // -> true
|
|
1089
1111
|
* ```
|
|
1112
|
+
* @category Creation
|
|
1090
1113
|
*/
|
|
1091
1114
|
export function createRelationships(store: Store): Relationships;
|