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/debug/ui-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, {useContext as useContext$1} from 'react';
|
|
2
2
|
|
|
3
3
|
const getTypeOf = (thing) => typeof thing;
|
|
4
4
|
const EMPTY_STRING = '';
|
|
@@ -735,22 +735,23 @@ const Provider = ({
|
|
|
735
735
|
checkpoints,
|
|
736
736
|
checkpointsById,
|
|
737
737
|
children,
|
|
738
|
-
}) =>
|
|
739
|
-
|
|
738
|
+
}) => {
|
|
739
|
+
const thingsOrThingsId = useContext$1(Context);
|
|
740
|
+
return /* @__PURE__ */ createElement(
|
|
740
741
|
Context.Provider,
|
|
741
742
|
{
|
|
742
743
|
value: useMemo(
|
|
743
744
|
() => [
|
|
744
|
-
store,
|
|
745
|
-
storesById,
|
|
746
|
-
metrics,
|
|
747
|
-
metricsById,
|
|
748
|
-
indexes,
|
|
749
|
-
indexesById,
|
|
750
|
-
relationships,
|
|
751
|
-
relationshipsById,
|
|
752
|
-
checkpoints,
|
|
753
|
-
checkpointsById,
|
|
745
|
+
store ?? thingsOrThingsId[0],
|
|
746
|
+
{...thingsOrThingsId[1], ...storesById},
|
|
747
|
+
metrics ?? thingsOrThingsId[2],
|
|
748
|
+
{...thingsOrThingsId[3], ...metricsById},
|
|
749
|
+
indexes ?? thingsOrThingsId[4],
|
|
750
|
+
{...thingsOrThingsId[5], ...indexesById},
|
|
751
|
+
relationships ?? thingsOrThingsId[6],
|
|
752
|
+
{...thingsOrThingsId[7], ...relationshipsById},
|
|
753
|
+
checkpoints ?? thingsOrThingsId[8],
|
|
754
|
+
{...thingsOrThingsId[9], ...checkpointsById},
|
|
754
755
|
],
|
|
755
756
|
[
|
|
756
757
|
store,
|
|
@@ -763,11 +764,13 @@ const Provider = ({
|
|
|
763
764
|
relationshipsById,
|
|
764
765
|
checkpoints,
|
|
765
766
|
checkpointsById,
|
|
767
|
+
thingsOrThingsId,
|
|
766
768
|
],
|
|
767
769
|
),
|
|
768
770
|
},
|
|
769
771
|
children,
|
|
770
772
|
);
|
|
773
|
+
};
|
|
771
774
|
const wrap = (children, separator, encloseWithId, id) => {
|
|
772
775
|
const separatedChildren =
|
|
773
776
|
isUndefined(separator) || !Array.isArray(children)
|
package/lib/indexes.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export type SortKey = string | number | boolean;
|
|
|
60
60
|
* When called, a SliceIdsListener is given a reference to the Indexes object,
|
|
61
61
|
* and the Id of the Index that changed.
|
|
62
62
|
*
|
|
63
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
64
|
+
* @param indexId The Id of the Index that changed.
|
|
63
65
|
* @category Listener
|
|
64
66
|
*/
|
|
65
67
|
export type SliceIdsListener = (indexes: Indexes, indexId: Id) => void;
|
|
@@ -75,6 +77,9 @@ export type SliceIdsListener = (indexes: Indexes, indexId: Id) => void;
|
|
|
75
77
|
* object, the Id of the Index that changed, and the Id of the Slice whose Row
|
|
76
78
|
* Ids changed.
|
|
77
79
|
*
|
|
80
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
81
|
+
* @param indexId The Id of the Index that changed.
|
|
82
|
+
* @param sliceId The Id of the Slice that changed.
|
|
78
83
|
* @category Listener
|
|
79
84
|
*/
|
|
80
85
|
export type SliceRowIdsListener = (
|
|
@@ -93,7 +98,13 @@ export type SliceRowIdsListener = (
|
|
|
93
98
|
* @category Development
|
|
94
99
|
*/
|
|
95
100
|
export type IndexesListenerStats = {
|
|
101
|
+
/**
|
|
102
|
+
* The number of SlideIdsListeners registered with the Indexes object.
|
|
103
|
+
*/
|
|
96
104
|
sliceIds?: number;
|
|
105
|
+
/**
|
|
106
|
+
* The number of SliceRowIdsListeners registered with the Indexes object.
|
|
107
|
+
*/
|
|
97
108
|
sliceRowIds?: number;
|
|
98
109
|
};
|
|
99
110
|
|
|
@@ -118,7 +129,7 @@ export type IndexesListenerStats = {
|
|
|
118
129
|
* creation, to adding a definition, getting its contents, and then registering
|
|
119
130
|
* and removing a listener for it.
|
|
120
131
|
*
|
|
121
|
-
* ```
|
|
132
|
+
* ```js
|
|
122
133
|
* const store = createStore().setTable('pets', {
|
|
123
134
|
* fido: {species: 'dog'},
|
|
124
135
|
* felix: {species: 'cat'},
|
|
@@ -146,6 +157,7 @@ export type IndexesListenerStats = {
|
|
|
146
157
|
* indexes.delListener(listenerId);
|
|
147
158
|
* indexes.destroy();
|
|
148
159
|
* ```
|
|
160
|
+
* @category Indexes
|
|
149
161
|
*/
|
|
150
162
|
export interface Indexes {
|
|
151
163
|
/**
|
|
@@ -211,7 +223,7 @@ export interface Indexes {
|
|
|
211
223
|
* This example creates a Store, creates an Indexes object, and defines a
|
|
212
224
|
* simple Index based on the values in the `species` Cell.
|
|
213
225
|
*
|
|
214
|
-
* ```
|
|
226
|
+
* ```js
|
|
215
227
|
* const store = createStore().setTable('pets', {
|
|
216
228
|
* fido: {species: 'dog'},
|
|
217
229
|
* felix: {species: 'cat'},
|
|
@@ -230,7 +242,7 @@ export interface Indexes {
|
|
|
230
242
|
* This example creates a Store, creates an Indexes object, and defines an
|
|
231
243
|
* Index based on the first letter of the pets' names.
|
|
232
244
|
*
|
|
233
|
-
* ```
|
|
245
|
+
* ```js
|
|
234
246
|
* const store = createStore().setTable('pets', {
|
|
235
247
|
* fido: {species: 'dog'},
|
|
236
248
|
* felix: {species: 'cat'},
|
|
@@ -250,7 +262,7 @@ export interface Indexes {
|
|
|
250
262
|
* Index based on the first letter of the pets' names. The Slice Ids (and Row
|
|
251
263
|
* Ids within them) are alphabetically sorted.
|
|
252
264
|
*
|
|
253
|
-
* ```
|
|
265
|
+
* ```js
|
|
254
266
|
* const store = createStore().setTable('pets', {
|
|
255
267
|
* fido: {species: 'dog'},
|
|
256
268
|
* felix: {species: 'cat'},
|
|
@@ -292,7 +304,7 @@ export interface Indexes {
|
|
|
292
304
|
* This example creates a Store, creates an Indexes object, defines a simple
|
|
293
305
|
* Index, and then removes it.
|
|
294
306
|
*
|
|
295
|
-
* ```
|
|
307
|
+
* ```js
|
|
296
308
|
* const store = createStore().setTable('pets', {
|
|
297
309
|
* fido: {species: 'dog'},
|
|
298
310
|
* felix: {species: 'cat'},
|
|
@@ -321,7 +333,7 @@ export interface Indexes {
|
|
|
321
333
|
* This example creates an Indexes object against a newly-created Store and
|
|
322
334
|
* then gets its reference in order to update its data.
|
|
323
335
|
*
|
|
324
|
-
* ```
|
|
336
|
+
* ```js
|
|
325
337
|
* const indexes = createIndexes(createStore());
|
|
326
338
|
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
327
339
|
* indexes.getStore().setCell('pets', 'fido', 'species', 'dog');
|
|
@@ -341,7 +353,7 @@ export interface Indexes {
|
|
|
341
353
|
* This example creates an Indexes object with two definitions, and then gets
|
|
342
354
|
* the Ids of the definitions.
|
|
343
355
|
*
|
|
344
|
-
* ```
|
|
356
|
+
* ```js
|
|
345
357
|
* const indexes = createIndexes(createStore())
|
|
346
358
|
* .setIndexDefinition('bySpecies', 'pets', 'species')
|
|
347
359
|
* .setIndexDefinition('byColor', 'pets', 'color');
|
|
@@ -365,7 +377,7 @@ export interface Indexes {
|
|
|
365
377
|
* This example creates an Indexes object, a single Index definition, and then
|
|
366
378
|
* queries it (and a non-existent definition) to get the underlying Table Id.
|
|
367
379
|
*
|
|
368
|
-
* ```
|
|
380
|
+
* ```js
|
|
369
381
|
* const indexes = createIndexes(createStore());
|
|
370
382
|
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
371
383
|
*
|
|
@@ -391,7 +403,7 @@ export interface Indexes {
|
|
|
391
403
|
* simple Index. It then uses getSliceIds to see the available Slice Ids in
|
|
392
404
|
* the Index (and also the Slice Ids in an Index that has not been defined).
|
|
393
405
|
*
|
|
394
|
-
* ```
|
|
406
|
+
* ```js
|
|
395
407
|
* const store = createStore().setTable('pets', {
|
|
396
408
|
* fido: {species: 'dog'},
|
|
397
409
|
* felix: {species: 'cat'},
|
|
@@ -425,7 +437,7 @@ export interface Indexes {
|
|
|
425
437
|
* simple Index. It then uses getSliceRowIds to see the Row Ids in the Slice
|
|
426
438
|
* (and also the Row Ids in Slices that do not exist).
|
|
427
439
|
*
|
|
428
|
-
* ```
|
|
440
|
+
* ```js
|
|
429
441
|
* const store = createStore().setTable('pets', {
|
|
430
442
|
* fido: {species: 'dog'},
|
|
431
443
|
* felix: {species: 'cat'},
|
|
@@ -467,7 +479,7 @@ export interface Indexes {
|
|
|
467
479
|
* This example creates a Store, a Indexes object, and then registers a
|
|
468
480
|
* listener that responds to any changes to a specific Index.
|
|
469
481
|
*
|
|
470
|
-
* ```
|
|
482
|
+
* ```js
|
|
471
483
|
* const store = createStore().setTable('pets', {
|
|
472
484
|
* fido: {species: 'dog'},
|
|
473
485
|
* felix: {species: 'cat'},
|
|
@@ -495,7 +507,7 @@ export interface Indexes {
|
|
|
495
507
|
* This example creates a Store, a Indexes object, and then registers a
|
|
496
508
|
* listener that responds to any changes to any Index.
|
|
497
509
|
*
|
|
498
|
-
* ```
|
|
510
|
+
* ```js
|
|
499
511
|
* const store = createStore().setTable('pets', {
|
|
500
512
|
* fido: {species: 'dog', color: 'brown'},
|
|
501
513
|
* felix: {species: 'cat', color: 'black'},
|
|
@@ -552,7 +564,7 @@ export interface Indexes {
|
|
|
552
564
|
* This example creates a Store, a Indexes object, and then registers a
|
|
553
565
|
* listener that responds to any changes to a specific Slice.
|
|
554
566
|
*
|
|
555
|
-
* ```
|
|
567
|
+
* ```js
|
|
556
568
|
* const store = createStore().setTable('pets', {
|
|
557
569
|
* fido: {species: 'dog'},
|
|
558
570
|
* felix: {species: 'cat'},
|
|
@@ -581,7 +593,7 @@ export interface Indexes {
|
|
|
581
593
|
* This example creates a Store, a Indexes object, and then registers a
|
|
582
594
|
* listener that responds to any changes to any Slice.
|
|
583
595
|
*
|
|
584
|
-
* ```
|
|
596
|
+
* ```js
|
|
585
597
|
* const store = createStore().setTable('pets', {
|
|
586
598
|
* fido: {species: 'dog', color: 'brown'},
|
|
587
599
|
* felix: {species: 'cat', color: 'black'},
|
|
@@ -633,7 +645,7 @@ export interface Indexes {
|
|
|
633
645
|
* This example creates a Store, a Indexes object, registers a listener, and
|
|
634
646
|
* then removes it.
|
|
635
647
|
*
|
|
636
|
-
* ```
|
|
648
|
+
* ```js
|
|
637
649
|
* const store = createStore().setTable('pets', {
|
|
638
650
|
* fido: {species: 'dog'},
|
|
639
651
|
* felix: {species: 'cat'},
|
|
@@ -675,7 +687,7 @@ export interface Indexes {
|
|
|
675
687
|
* definition (that registers a RowListener with the underlying Store),
|
|
676
688
|
* and then destroys it again, removing the listener.
|
|
677
689
|
*
|
|
678
|
-
* ```
|
|
690
|
+
* ```js
|
|
679
691
|
* const store = createStore().setTable('pets', {
|
|
680
692
|
* fido: {species: 'dog'},
|
|
681
693
|
* felix: {species: 'cat'},
|
|
@@ -714,7 +726,7 @@ export interface Indexes {
|
|
|
714
726
|
* @example
|
|
715
727
|
* This example gets the listener statistics of an Indexes object.
|
|
716
728
|
*
|
|
717
|
-
* ```
|
|
729
|
+
* ```js
|
|
718
730
|
* const store = createStore();
|
|
719
731
|
* const indexes = createIndexes(store);
|
|
720
732
|
* indexes.addSliceIdsListener(null, () => {
|
|
@@ -747,7 +759,7 @@ export interface Indexes {
|
|
|
747
759
|
* @example
|
|
748
760
|
* This example creates an Indexes object.
|
|
749
761
|
*
|
|
750
|
-
* ```
|
|
762
|
+
* ```js
|
|
751
763
|
* const store = createStore();
|
|
752
764
|
* const indexes = createIndexes(store);
|
|
753
765
|
* console.log(indexes.getIndexIds());
|
|
@@ -757,13 +769,14 @@ export interface Indexes {
|
|
|
757
769
|
* This example creates an Indexes object, and calls the method a second time
|
|
758
770
|
* for the same Store to return the same object.
|
|
759
771
|
*
|
|
760
|
-
* ```
|
|
772
|
+
* ```js
|
|
761
773
|
* const store = createStore();
|
|
762
774
|
* const indexes1 = createIndexes(store);
|
|
763
775
|
* const indexes2 = createIndexes(store);
|
|
764
776
|
* console.log(indexes1 === indexes2);
|
|
765
777
|
* // -> true
|
|
766
778
|
* ```
|
|
779
|
+
* @category Creation
|
|
767
780
|
*/
|
|
768
781
|
export function createIndexes(store: Store): Indexes;
|
|
769
782
|
|
|
@@ -778,7 +791,7 @@ export function createIndexes(store: Store): Indexes;
|
|
|
778
791
|
* @example
|
|
779
792
|
* This example creates an Indexes object.
|
|
780
793
|
*
|
|
781
|
-
* ```
|
|
794
|
+
* ```js
|
|
782
795
|
* const store = createStore();
|
|
783
796
|
* const indexes = createIndexes(store);
|
|
784
797
|
* console.log(indexes.getIndexIds());
|
|
@@ -789,7 +802,7 @@ export function createIndexes(store: Store): Indexes;
|
|
|
789
802
|
* Index based on the first letter of the pets' names. The Slice Ids (and Row
|
|
790
803
|
* Ids within them) are alphabetically sorted using the defaultSorter function.
|
|
791
804
|
*
|
|
792
|
-
* ```
|
|
805
|
+
* ```js
|
|
793
806
|
* const store = createStore().setTable('pets', {
|
|
794
807
|
* fido: {species: 'dog'},
|
|
795
808
|
* felix: {species: 'cat'},
|
|
@@ -811,5 +824,6 @@ export function createIndexes(store: Store): Indexes;
|
|
|
811
824
|
* console.log(indexes.getSliceRowIds('byFirst', 'f'));
|
|
812
825
|
* // -> ['felix', 'fido']
|
|
813
826
|
* ```
|
|
827
|
+
* @category Convenience
|
|
814
828
|
*/
|
|
815
829
|
export function defaultSorter(sortKey1: SortKey, sortKey2: SortKey): number;
|
package/lib/metrics.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ export type Metric = number;
|
|
|
31
31
|
* use a more complex aggregation of your own devising. See the
|
|
32
32
|
* setMetricDefinition method for more examples.
|
|
33
33
|
*
|
|
34
|
+
* @param numbers The array of numbers in the Metric's aggregation.
|
|
35
|
+
* @param length The length of the array of numbers in the Metric's aggregation.
|
|
36
|
+
* @returns The value of the Metric.
|
|
34
37
|
* @category Aggregators
|
|
35
38
|
*/
|
|
36
39
|
export type Aggregate = (numbers: number[], length: number) => Metric;
|
|
@@ -53,6 +56,10 @@ export type Aggregate = (numbers: number[], length: number) => Metric;
|
|
|
53
56
|
* cost of growing the input data set. See the setMetricDefinition method for
|
|
54
57
|
* more examples.
|
|
55
58
|
*
|
|
59
|
+
* @param metric The current value of the Metric.
|
|
60
|
+
* @param add The number being added to the Metric's aggregation.
|
|
61
|
+
* @param length The length of the array of numbers in the Metric's aggregation.
|
|
62
|
+
* @returns The new value of the Metric.
|
|
56
63
|
* @category Aggregators
|
|
57
64
|
*/
|
|
58
65
|
export type AggregateAdd = (
|
|
@@ -82,6 +89,10 @@ export type AggregateAdd = (
|
|
|
82
89
|
* cost of shrinking the input data set. See the setMetricDefinition method for
|
|
83
90
|
* more examples.
|
|
84
91
|
*
|
|
92
|
+
* @param metric The current value of the Metric.
|
|
93
|
+
* @param remove The number being removed from the Metric's aggregation.
|
|
94
|
+
* @param length The length of the array of numbers in the Metric's aggregation.
|
|
95
|
+
* @returns The new value of the Metric.
|
|
85
96
|
* @category Aggregators
|
|
86
97
|
*/
|
|
87
98
|
export type AggregateRemove = (
|
|
@@ -109,6 +120,11 @@ export type AggregateRemove = (
|
|
|
109
120
|
* cost of changing the input data set in place. See the setMetricDefinition
|
|
110
121
|
* method for more examples.
|
|
111
122
|
*
|
|
123
|
+
* @param metric The current value of the Metric.
|
|
124
|
+
* @param add The number being added to the Metric's aggregation.
|
|
125
|
+
* @param remove The number being removed from the Metric's aggregation.
|
|
126
|
+
* @param length The length of the array of numbers in the Metric's aggregation.
|
|
127
|
+
* @returns The new value of the Metric.
|
|
112
128
|
* @category Aggregators
|
|
113
129
|
*/
|
|
114
130
|
export type AggregateReplace = (
|
|
@@ -132,6 +148,10 @@ export type AggregateReplace = (
|
|
|
132
148
|
* has gained its first row), the old value will be `undefined`. If a Metric now
|
|
133
149
|
* no longer has a value, the new value will be `undefined`.
|
|
134
150
|
*
|
|
151
|
+
* @param metrics A reference to the Metrics object that changed.
|
|
152
|
+
* @param metricId The Id of the Metric that changed.
|
|
153
|
+
* @param newMetric The new value of the Metric that changed.
|
|
154
|
+
* @param oldMetric The old value of the Metric that changed.
|
|
135
155
|
* @category Listener
|
|
136
156
|
*/
|
|
137
157
|
export type MetricListener = (
|
|
@@ -151,6 +171,9 @@ export type MetricListener = (
|
|
|
151
171
|
* @category Development
|
|
152
172
|
*/
|
|
153
173
|
export type MetricsListenerStats = {
|
|
174
|
+
/**
|
|
175
|
+
* The number of MetricListeners registered with the Metrics object.
|
|
176
|
+
*/
|
|
154
177
|
metric?: number;
|
|
155
178
|
};
|
|
156
179
|
|
|
@@ -176,7 +199,7 @@ export type MetricsListenerStats = {
|
|
|
176
199
|
* creation, to adding a definition, getting an Metric, and then registering and
|
|
177
200
|
* removing a listener for it.
|
|
178
201
|
*
|
|
179
|
-
* ```
|
|
202
|
+
* ```js
|
|
180
203
|
* const store = createStore().setTable('species', {
|
|
181
204
|
* dog: {price: 5},
|
|
182
205
|
* cat: {price: 4},
|
|
@@ -203,6 +226,7 @@ export type MetricsListenerStats = {
|
|
|
203
226
|
* metrics.delListener(listenerId);
|
|
204
227
|
* metrics.destroy();
|
|
205
228
|
* ```
|
|
229
|
+
* @category Metrics
|
|
206
230
|
*/
|
|
207
231
|
export interface Metrics {
|
|
208
232
|
/**
|
|
@@ -258,7 +282,7 @@ export interface Metrics {
|
|
|
258
282
|
* This example creates a Store, creates a Metrics object, and defines a
|
|
259
283
|
* simple Metric to count the Row objects in the Table.
|
|
260
284
|
*
|
|
261
|
-
* ```
|
|
285
|
+
* ```js
|
|
262
286
|
* const store = createStore().setTable('species', {
|
|
263
287
|
* dog: {price: 5},
|
|
264
288
|
* cat: {price: 4},
|
|
@@ -276,7 +300,7 @@ export interface Metrics {
|
|
|
276
300
|
* standard Metric to get the highest value of each `price` Cell in the Row
|
|
277
301
|
* objects in the Table.
|
|
278
302
|
*
|
|
279
|
-
* ```
|
|
303
|
+
* ```js
|
|
280
304
|
* const store = createStore().setTable('species', {
|
|
281
305
|
* dog: {price: 5},
|
|
282
306
|
* cat: {price: 4},
|
|
@@ -293,7 +317,7 @@ export interface Metrics {
|
|
|
293
317
|
* This example creates a Store, creates a Metrics object, and defines a
|
|
294
318
|
* custom Metric to get the lowest value of each `price` Cell, greater than 2.
|
|
295
319
|
*
|
|
296
|
-
* ```
|
|
320
|
+
* ```js
|
|
297
321
|
* const store = createStore().setTable('species', {
|
|
298
322
|
* dog: {price: 5},
|
|
299
323
|
* cat: {price: 4},
|
|
@@ -317,7 +341,7 @@ export interface Metrics {
|
|
|
317
341
|
* However, it also reduces algorithmic complexity with two shortcut
|
|
318
342
|
* functions.
|
|
319
343
|
*
|
|
320
|
-
* ```
|
|
344
|
+
* ```js
|
|
321
345
|
* const store = createStore().setTable('species', {
|
|
322
346
|
* dog: {price: 5},
|
|
323
347
|
* cat: {price: 4},
|
|
@@ -350,7 +374,7 @@ export interface Metrics {
|
|
|
350
374
|
* This example creates a Store, creates a Metrics object, and defines a
|
|
351
375
|
* custom Metric to get the average value of a discounted price.
|
|
352
376
|
*
|
|
353
|
-
* ```
|
|
377
|
+
* ```js
|
|
354
378
|
* const store = createStore().setTable('species', {
|
|
355
379
|
* dog: {price: 5, discount: 0.3},
|
|
356
380
|
* cat: {price: 4, discount: 0.2},
|
|
@@ -389,7 +413,7 @@ export interface Metrics {
|
|
|
389
413
|
* This example creates a Store, creates a Metrics object, defines a simple
|
|
390
414
|
* Metric, and then removes it.
|
|
391
415
|
*
|
|
392
|
-
* ```
|
|
416
|
+
* ```js
|
|
393
417
|
* const store = createStore().setTable('species', {
|
|
394
418
|
* dog: {price: 5},
|
|
395
419
|
* cat: {price: 4},
|
|
@@ -418,7 +442,7 @@ export interface Metrics {
|
|
|
418
442
|
* This example creates a Metrics object against a newly-created Store and
|
|
419
443
|
* then gets its reference in order to update its data.
|
|
420
444
|
*
|
|
421
|
-
* ```
|
|
445
|
+
* ```js
|
|
422
446
|
* const metrics = createMetrics(createStore());
|
|
423
447
|
* metrics.setMetricDefinition('speciesCount', 'species');
|
|
424
448
|
* metrics.getStore().setCell('species', 'dog', 'price', 5);
|
|
@@ -438,7 +462,7 @@ export interface Metrics {
|
|
|
438
462
|
* This example creates a Metrics object with two definitions, and then gets
|
|
439
463
|
* the Ids of the definitions.
|
|
440
464
|
*
|
|
441
|
-
* ```
|
|
465
|
+
* ```js
|
|
442
466
|
* const metrics = createMetrics(createStore())
|
|
443
467
|
* .setMetricDefinition('speciesCount', 'species')
|
|
444
468
|
* .setMetricDefinition('petsCount', 'pets');
|
|
@@ -462,7 +486,7 @@ export interface Metrics {
|
|
|
462
486
|
* This example creates a Metrics object, a single Metric definition, and then
|
|
463
487
|
* queries it (and a non-existent definition) to get the underlying Table Id.
|
|
464
488
|
*
|
|
465
|
-
* ```
|
|
489
|
+
* ```js
|
|
466
490
|
* const metrics = createMetrics(createStore());
|
|
467
491
|
* metrics.setMetricDefinition('speciesCount', 'species');
|
|
468
492
|
*
|
|
@@ -489,7 +513,7 @@ export interface Metrics {
|
|
|
489
513
|
* getMetric to access its value (and also the value of a Metric that has not
|
|
490
514
|
* been defined).
|
|
491
515
|
*
|
|
492
|
-
* ```
|
|
516
|
+
* ```js
|
|
493
517
|
* const store = createStore().setTable('species', {
|
|
494
518
|
* dog: {price: 5},
|
|
495
519
|
* cat: {price: 4},
|
|
@@ -529,7 +553,7 @@ export interface Metrics {
|
|
|
529
553
|
* This example creates a Store, a Metrics object, and then registers a
|
|
530
554
|
* listener that responds to any changes to a specific Metric.
|
|
531
555
|
*
|
|
532
|
-
* ```
|
|
556
|
+
* ```js
|
|
533
557
|
* const store = createStore().setTable('species', {
|
|
534
558
|
* dog: {price: 5},
|
|
535
559
|
* cat: {price: 4},
|
|
@@ -557,7 +581,7 @@ export interface Metrics {
|
|
|
557
581
|
* This example creates a Store, a Metrics object, and then registers a
|
|
558
582
|
* listener that responds to any changes to any Metric.
|
|
559
583
|
*
|
|
560
|
-
* ```
|
|
584
|
+
* ```js
|
|
561
585
|
* const store = createStore().setTable('species', {
|
|
562
586
|
* dog: {price: 5},
|
|
563
587
|
* cat: {price: 4},
|
|
@@ -601,7 +625,7 @@ export interface Metrics {
|
|
|
601
625
|
* This example creates a Store, a Metrics object, registers a listener, and
|
|
602
626
|
* then removes it.
|
|
603
627
|
*
|
|
604
|
-
* ```
|
|
628
|
+
* ```js
|
|
605
629
|
* const store = createStore().setTable('species', {
|
|
606
630
|
* dog: {price: 5},
|
|
607
631
|
* cat: {price: 4},
|
|
@@ -643,7 +667,7 @@ export interface Metrics {
|
|
|
643
667
|
* registers a RowListener with the underlying Store), and then destroys it
|
|
644
668
|
* again, removing the listener.
|
|
645
669
|
*
|
|
646
|
-
* ```
|
|
670
|
+
* ```js
|
|
647
671
|
* const store = createStore().setTable('species', {
|
|
648
672
|
* dog: {price: 5},
|
|
649
673
|
* cat: {price: 4},
|
|
@@ -679,7 +703,7 @@ export interface Metrics {
|
|
|
679
703
|
* @example
|
|
680
704
|
* This example gets the listener statistics of a Metrics object.
|
|
681
705
|
*
|
|
682
|
-
* ```
|
|
706
|
+
* ```js
|
|
683
707
|
* const store = createStore();
|
|
684
708
|
* const metrics = createMetrics(store);
|
|
685
709
|
* metrics.addMetricListener(null, () => console.log('Metric changed'));
|
|
@@ -707,7 +731,7 @@ export interface Metrics {
|
|
|
707
731
|
* @example
|
|
708
732
|
* This example creates a Metrics object.
|
|
709
733
|
*
|
|
710
|
-
* ```
|
|
734
|
+
* ```js
|
|
711
735
|
* const store = createStore();
|
|
712
736
|
* const metrics = createMetrics(store);
|
|
713
737
|
* console.log(metrics.getMetricIds());
|
|
@@ -717,12 +741,13 @@ export interface Metrics {
|
|
|
717
741
|
* This example creates a Metrics object, and calls the method a second time
|
|
718
742
|
* for the same Store to return the same object.
|
|
719
743
|
*
|
|
720
|
-
* ```
|
|
744
|
+
* ```js
|
|
721
745
|
* const store = createStore();
|
|
722
746
|
* const metrics1 = createMetrics(store);
|
|
723
747
|
* const metrics2 = createMetrics(store);
|
|
724
748
|
* console.log(metrics1 === metrics2);
|
|
725
749
|
* // -> true
|
|
726
750
|
* ```
|
|
751
|
+
* @category Creation
|
|
727
752
|
*/
|
|
728
753
|
export function createMetrics(store: Store): Metrics;
|