react-native-onyx 2.0.80 → 2.0.81
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/API.md +24 -0
- package/dist/Onyx.d.ts +16 -0
- package/dist/Onyx.js +34 -0
- package/dist/OnyxUtils.d.ts +2 -0
- package/dist/OnyxUtils.js +1 -0
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -50,6 +50,10 @@ value will be saved to storage after the default value.</p>
|
|
|
50
50
|
<dt><a href="#update">update(data)</a> ⇒</dt>
|
|
51
51
|
<dd><p>Insert API responses and lifecycle data into Onyx</p>
|
|
52
52
|
</dd>
|
|
53
|
+
<dt><a href="#setCollection">setCollection(collectionKey, collection)</a></dt>
|
|
54
|
+
<dd><p>Sets a collection by replacing all existing collection members with new values.
|
|
55
|
+
Any existing collection members not included in the new data will be removed.</p>
|
|
56
|
+
</dd>
|
|
53
57
|
</dl>
|
|
54
58
|
|
|
55
59
|
<a name="init"></a>
|
|
@@ -209,3 +213,23 @@ Insert API responses and lifecycle data into Onyx
|
|
|
209
213
|
| --- | --- |
|
|
210
214
|
| data | An array of objects with update expressions |
|
|
211
215
|
|
|
216
|
+
<a name="setCollection"></a>
|
|
217
|
+
|
|
218
|
+
## setCollection(collectionKey, collection)
|
|
219
|
+
Sets a collection by replacing all existing collection members with new values.
|
|
220
|
+
Any existing collection members not included in the new data will be removed.
|
|
221
|
+
|
|
222
|
+
**Kind**: global function
|
|
223
|
+
|
|
224
|
+
| Param | Description |
|
|
225
|
+
| --- | --- |
|
|
226
|
+
| collectionKey | e.g. `ONYXKEYS.COLLECTION.REPORT` |
|
|
227
|
+
| collection | Object collection keyed by individual collection member keys and values |
|
|
228
|
+
|
|
229
|
+
**Example**
|
|
230
|
+
```js
|
|
231
|
+
Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
232
|
+
[`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
|
|
233
|
+
[`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
234
|
+
});
|
|
235
|
+
```
|
package/dist/Onyx.d.ts
CHANGED
|
@@ -119,11 +119,26 @@ declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
|
|
|
119
119
|
* @returns resolves when all operations are complete
|
|
120
120
|
*/
|
|
121
121
|
declare function update(data: OnyxUpdate[]): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Sets a collection by replacing all existing collection members with new values.
|
|
124
|
+
* Any existing collection members not included in the new data will be removed.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
128
|
+
* [`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
|
|
129
|
+
* [`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
133
|
+
* @param collection Object collection keyed by individual collection member keys and values
|
|
134
|
+
*/
|
|
135
|
+
declare function setCollection<TKey extends CollectionKeyBase, TMap extends string>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TMap>): Promise<void>;
|
|
122
136
|
declare const Onyx: {
|
|
123
137
|
readonly METHOD: {
|
|
124
138
|
readonly SET: "set";
|
|
125
139
|
readonly MERGE: "merge";
|
|
126
140
|
readonly MERGE_COLLECTION: "mergecollection";
|
|
141
|
+
readonly SET_COLLECTION: "setcollection";
|
|
127
142
|
readonly MULTI_SET: "multiset";
|
|
128
143
|
readonly CLEAR: "clear";
|
|
129
144
|
};
|
|
@@ -133,6 +148,7 @@ declare const Onyx: {
|
|
|
133
148
|
readonly multiSet: typeof multiSet;
|
|
134
149
|
readonly merge: typeof merge;
|
|
135
150
|
readonly mergeCollection: typeof mergeCollection;
|
|
151
|
+
readonly setCollection: typeof setCollection;
|
|
136
152
|
readonly update: typeof update;
|
|
137
153
|
readonly clear: typeof clear;
|
|
138
154
|
readonly init: typeof init;
|
package/dist/Onyx.js
CHANGED
|
@@ -632,6 +632,39 @@ function update(data) {
|
|
|
632
632
|
.then(() => updateSnapshots(data))
|
|
633
633
|
.then(() => undefined);
|
|
634
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* Sets a collection by replacing all existing collection members with new values.
|
|
637
|
+
* Any existing collection members not included in the new data will be removed.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
641
|
+
* [`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
|
|
642
|
+
* [`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
643
|
+
* });
|
|
644
|
+
*
|
|
645
|
+
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
646
|
+
* @param collection Object collection keyed by individual collection member keys and values
|
|
647
|
+
*/
|
|
648
|
+
function setCollection(collectionKey, collection) {
|
|
649
|
+
const newCollectionKeys = Object.keys(collection);
|
|
650
|
+
if (!OnyxUtils_1.default.doAllCollectionItemsBelongToSameParent(collectionKey, newCollectionKeys)) {
|
|
651
|
+
Logger.logAlert(`setCollection called with keys that do not belong to the same parent ${collectionKey}. Skipping this update.`);
|
|
652
|
+
return Promise.resolve();
|
|
653
|
+
}
|
|
654
|
+
return OnyxUtils_1.default.getAllKeys().then((persistedKeys) => {
|
|
655
|
+
const mutableCollection = Object.assign({}, collection);
|
|
656
|
+
persistedKeys.forEach((key) => {
|
|
657
|
+
if (!key.startsWith(collectionKey)) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (newCollectionKeys.includes(key)) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
mutableCollection[key] = null;
|
|
664
|
+
});
|
|
665
|
+
return multiSet(mutableCollection);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
635
668
|
const Onyx = {
|
|
636
669
|
METHOD: OnyxUtils_1.default.METHOD,
|
|
637
670
|
connect,
|
|
@@ -640,6 +673,7 @@ const Onyx = {
|
|
|
640
673
|
multiSet,
|
|
641
674
|
merge,
|
|
642
675
|
mergeCollection,
|
|
676
|
+
setCollection,
|
|
643
677
|
update,
|
|
644
678
|
clear,
|
|
645
679
|
init,
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const METHOD: {
|
|
|
6
6
|
readonly SET: "set";
|
|
7
7
|
readonly MERGE: "merge";
|
|
8
8
|
readonly MERGE_COLLECTION: "mergecollection";
|
|
9
|
+
readonly SET_COLLECTION: "setcollection";
|
|
9
10
|
readonly MULTI_SET: "multiset";
|
|
10
11
|
readonly CLEAR: "clear";
|
|
11
12
|
};
|
|
@@ -228,6 +229,7 @@ declare const OnyxUtils: {
|
|
|
228
229
|
readonly SET: "set";
|
|
229
230
|
readonly MERGE: "merge";
|
|
230
231
|
readonly MERGE_COLLECTION: "mergecollection";
|
|
232
|
+
readonly SET_COLLECTION: "setcollection";
|
|
231
233
|
readonly MULTI_SET: "multiset";
|
|
232
234
|
readonly CLEAR: "clear";
|
|
233
235
|
};
|
package/dist/OnyxUtils.js
CHANGED