@ibodr/store 0.2.5 → 0.2.7
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/dist/index.d.ts +45 -7
- package/dist/index.mjs +250 -209
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -104,6 +104,36 @@ declare class AtomMap<K, V> implements Map<K, V> {
|
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
106
|
set(key: K, value: V): this;
|
|
107
|
+
/**
|
|
108
|
+
* Gets the value associated with a key, inserting `defaultValue` first if the key doesn't exist.
|
|
109
|
+
* This method is reactive and will cause reactive contexts to update when the value changes.
|
|
110
|
+
*
|
|
111
|
+
* @param key - The key to retrieve the value for
|
|
112
|
+
* @param defaultValue - The value to insert if the key doesn't exist
|
|
113
|
+
* @returns The existing value, or `defaultValue` if the key was missing
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const map = new AtomMap('myMap')
|
|
117
|
+
* console.log(map.getOrInsert('count', 0)) // 0, and 'count' is now set
|
|
118
|
+
* console.log(map.getOrInsert('count', 10)) // 0
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
getOrInsert(key: K, defaultValue: V): V;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the value associated with a key, inserting the result of `callback` first if the key
|
|
124
|
+
* doesn't exist. The callback only runs when the key is missing.
|
|
125
|
+
* This method is reactive and will cause reactive contexts to update when the value changes.
|
|
126
|
+
*
|
|
127
|
+
* @param key - The key to retrieve the value for
|
|
128
|
+
* @param callback - Called with the key to produce the value to insert
|
|
129
|
+
* @returns The existing value, or the newly computed value if the key was missing
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const map = new AtomMap<string, string[]>('myMap')
|
|
133
|
+
* map.getOrInsertComputed('tags', () => []).push('new')
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
getOrInsertComputed(key: K, callback: (key: K) => V): V;
|
|
107
137
|
/**
|
|
108
138
|
* Updates an existing value using an updater function.
|
|
109
139
|
*
|
|
@@ -555,6 +585,10 @@ declare function squashRecordDiffs<T extends UnknownRecord>(diffs: RecordsDiff<T
|
|
|
555
585
|
* - Updated records: Chain updates together, preserving the original 'from' state
|
|
556
586
|
* - Removed records: If the record was added in this sequence, cancel both operations
|
|
557
587
|
*
|
|
588
|
+
* The target's `updated` tuples are mutated in place, so the target must own them: start from
|
|
589
|
+
* `createEmptyRecordsDiff()` (or a diff built by earlier squashes into it) rather than a diff whose
|
|
590
|
+
* tuples are shared with another holder.
|
|
591
|
+
*
|
|
558
592
|
* @param target - The diff to modify in-place (will be mutated)
|
|
559
593
|
* @param diffs - Array of diffs to apply to the target
|
|
560
594
|
* @example
|
|
@@ -581,7 +615,7 @@ declare function squashRecordDiffs<T extends UnknownRecord>(diffs: RecordsDiff<T
|
|
|
581
615
|
*
|
|
582
616
|
* @internal
|
|
583
617
|
*/
|
|
584
|
-
declare function squashRecordDiffsMutable<T extends UnknownRecord>(target: RecordsDiff<T>, diffs: RecordsDiff<T>[]): void;
|
|
618
|
+
declare function squashRecordDiffsMutable<T extends UnknownRecord>(target: RecordsDiff<T>, diffs: RecordsDiff<T>[], fromIndex?: number): void;
|
|
585
619
|
|
|
586
620
|
/**
|
|
587
621
|
* Defines the scope of the record
|
|
@@ -1419,6 +1453,7 @@ declare class StoreSchema<R extends UnknownRecord, P = unknown> {
|
|
|
1419
1453
|
* @public
|
|
1420
1454
|
*/
|
|
1421
1455
|
getMigrationsSince(persistedSchema: SerializedSchema): Result<Migration[], string>;
|
|
1456
|
+
private computeMigrationsSince;
|
|
1422
1457
|
/**
|
|
1423
1458
|
* Migrates a single persisted record to match the current schema version.
|
|
1424
1459
|
*
|
|
@@ -1748,6 +1783,7 @@ declare class StoreSideEffects<R extends UnknownRecord> {
|
|
|
1748
1783
|
private _afterDeleteHandlers;
|
|
1749
1784
|
private _operationCompleteHandlers;
|
|
1750
1785
|
private _isEnabled;
|
|
1786
|
+
private addHandler;
|
|
1751
1787
|
/**
|
|
1752
1788
|
* Checks whether side effects are currently enabled.
|
|
1753
1789
|
* When disabled, all side effect handlers are bypassed.
|
|
@@ -2423,7 +2459,7 @@ declare class Store<R extends UnknownRecord = UnknownRecord, Props = unknown> {
|
|
|
2423
2459
|
*/
|
|
2424
2460
|
private historyReactor;
|
|
2425
2461
|
/**
|
|
2426
|
-
*
|
|
2462
|
+
* Cancels the history flush scheduled for the next frame, if any.
|
|
2427
2463
|
*
|
|
2428
2464
|
* @internal
|
|
2429
2465
|
*/
|
|
@@ -2959,17 +2995,19 @@ declare class StoreQueries<R extends UnknownRecord> {
|
|
|
2959
2995
|
* have been added, updated, or removed.
|
|
2960
2996
|
*
|
|
2961
2997
|
* @param typeName - The type name to filter the history by
|
|
2962
|
-
* @returns A computed value containing
|
|
2998
|
+
* @returns A computed value containing a change counter and diffs of changes for the specified type
|
|
2963
2999
|
*
|
|
2964
3000
|
* @example
|
|
2965
3001
|
* ```ts
|
|
2966
3002
|
* // Track changes to book records only
|
|
2967
3003
|
* const bookHistory = store.query.filterHistory('book')
|
|
2968
3004
|
*
|
|
2969
|
-
* //
|
|
2970
|
-
* react('book-changes', () => {
|
|
2971
|
-
* const
|
|
2972
|
-
*
|
|
3005
|
+
* // Log the books added since the last run
|
|
3006
|
+
* react('book-changes', (lastReactedEpoch) => {
|
|
3007
|
+
* const diffs = bookHistory.getDiffSince(lastReactedEpoch)
|
|
3008
|
+
* // no diffs to give, e.g. on the first run: rebuild anything derived from scratch
|
|
3009
|
+
* if (diffs === RESET_VALUE) return
|
|
3010
|
+
* for (const diff of diffs) console.log('Added:', Object.keys(diff.added))
|
|
2973
3011
|
* })
|
|
2974
3012
|
* ```
|
|
2975
3013
|
*
|