react-native-onyx 2.0.140 → 2.0.141
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/Onyx.js +1 -1
- package/dist/OnyxUtils.d.ts +9 -0
- package/dist/OnyxUtils.js +48 -0
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -567,7 +567,7 @@ function update(data) {
|
|
|
567
567
|
promises.push(() => OnyxUtils_1.default.mergeCollectionWithPatches(collectionKey, batchedCollectionUpdates.merge, batchedCollectionUpdates.mergeReplaceNullPatches));
|
|
568
568
|
}
|
|
569
569
|
if (!utils_1.default.isEmptyObject(batchedCollectionUpdates.set)) {
|
|
570
|
-
promises.push(() =>
|
|
570
|
+
promises.push(() => OnyxUtils_1.default.partialSetCollection(collectionKey, batchedCollectionUpdates.set));
|
|
571
571
|
}
|
|
572
572
|
});
|
|
573
573
|
Object.entries(updateQueue).forEach(([key, operations]) => {
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -255,6 +255,14 @@ declare function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge)
|
|
|
255
255
|
* tuples that we'll use to replace the nested objects of that collection member record with something else.
|
|
256
256
|
*/
|
|
257
257
|
declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>, mergeReplaceNullPatches?: MultiMergeReplaceNullPatches): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Sets keys in a collection by replacing all targeted collection members with new values.
|
|
260
|
+
* Any existing collection members not included in the new data will not be removed.
|
|
261
|
+
*
|
|
262
|
+
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
263
|
+
* @param collection Object collection keyed by individual collection member keys and values
|
|
264
|
+
*/
|
|
265
|
+
declare function partialSetCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>): Promise<void>;
|
|
258
266
|
declare function logKeyChanged(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey, value: unknown, hasChanged: boolean): void;
|
|
259
267
|
declare function logKeyRemoved(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey): void;
|
|
260
268
|
/**
|
|
@@ -318,6 +326,7 @@ declare const OnyxUtils: {
|
|
|
318
326
|
reduceCollectionWithSelector: typeof reduceCollectionWithSelector;
|
|
319
327
|
updateSnapshots: typeof updateSnapshots;
|
|
320
328
|
mergeCollectionWithPatches: typeof mergeCollectionWithPatches;
|
|
329
|
+
partialSetCollection: typeof partialSetCollection;
|
|
321
330
|
logKeyChanged: typeof logKeyChanged;
|
|
322
331
|
logKeyRemoved: typeof logKeyRemoved;
|
|
323
332
|
};
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -1322,6 +1322,53 @@ function mergeCollectionWithPatches(collectionKey, collection, mergeReplaceNullP
|
|
|
1322
1322
|
})
|
|
1323
1323
|
.then(() => undefined);
|
|
1324
1324
|
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Sets keys in a collection by replacing all targeted collection members with new values.
|
|
1327
|
+
* Any existing collection members not included in the new data will not be removed.
|
|
1328
|
+
*
|
|
1329
|
+
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
1330
|
+
* @param collection Object collection keyed by individual collection member keys and values
|
|
1331
|
+
*/
|
|
1332
|
+
function partialSetCollection(collectionKey, collection) {
|
|
1333
|
+
let resultCollection = collection;
|
|
1334
|
+
let resultCollectionKeys = Object.keys(resultCollection);
|
|
1335
|
+
// Confirm all the collection keys belong to the same parent
|
|
1336
|
+
if (!doAllCollectionItemsBelongToSameParent(collectionKey, resultCollectionKeys)) {
|
|
1337
|
+
Logger.logAlert(`setCollection called with keys that do not belong to the same parent ${collectionKey}. Skipping this update.`);
|
|
1338
|
+
return Promise.resolve();
|
|
1339
|
+
}
|
|
1340
|
+
if (skippableCollectionMemberIDs.size) {
|
|
1341
|
+
resultCollection = resultCollectionKeys.reduce((result, key) => {
|
|
1342
|
+
try {
|
|
1343
|
+
const [, collectionMemberID] = splitCollectionMemberKey(key, collectionKey);
|
|
1344
|
+
// If the collection member key is a skippable one we set its value to null.
|
|
1345
|
+
// eslint-disable-next-line no-param-reassign
|
|
1346
|
+
result[key] = !skippableCollectionMemberIDs.has(collectionMemberID) ? resultCollection[key] : null;
|
|
1347
|
+
}
|
|
1348
|
+
catch (_a) {
|
|
1349
|
+
// Something went wrong during split, so we assign the data to result anyway.
|
|
1350
|
+
// eslint-disable-next-line no-param-reassign
|
|
1351
|
+
result[key] = resultCollection[key];
|
|
1352
|
+
}
|
|
1353
|
+
return result;
|
|
1354
|
+
}, {});
|
|
1355
|
+
}
|
|
1356
|
+
resultCollectionKeys = Object.keys(resultCollection);
|
|
1357
|
+
return getAllKeys().then((persistedKeys) => {
|
|
1358
|
+
const mutableCollection = Object.assign({}, resultCollection);
|
|
1359
|
+
const existingKeys = resultCollectionKeys.filter((key) => persistedKeys.has(key));
|
|
1360
|
+
const previousCollection = getCachedCollection(collectionKey, existingKeys);
|
|
1361
|
+
const keyValuePairs = prepareKeyValuePairsForStorage(mutableCollection, true);
|
|
1362
|
+
keyValuePairs.forEach(([key, value]) => OnyxCache_1.default.set(key, value));
|
|
1363
|
+
const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
|
|
1364
|
+
return storage_1.default.multiSet(keyValuePairs)
|
|
1365
|
+
.catch((error) => evictStorageAndRetry(error, partialSetCollection, collectionKey, collection))
|
|
1366
|
+
.then(() => {
|
|
1367
|
+
sendActionToDevTools(METHOD.SET_COLLECTION, undefined, mutableCollection);
|
|
1368
|
+
return updatePromise;
|
|
1369
|
+
});
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1325
1372
|
function logKeyChanged(onyxMethod, key, value, hasChanged) {
|
|
1326
1373
|
Logger.logInfo(`${onyxMethod} called for key: ${key}${underscore_1.default.isObject(value) ? ` properties: ${underscore_1.default.keys(value).join(',')}` : ''} hasChanged: ${hasChanged}`);
|
|
1327
1374
|
}
|
|
@@ -1389,6 +1436,7 @@ const OnyxUtils = {
|
|
|
1389
1436
|
reduceCollectionWithSelector,
|
|
1390
1437
|
updateSnapshots,
|
|
1391
1438
|
mergeCollectionWithPatches,
|
|
1439
|
+
partialSetCollection,
|
|
1392
1440
|
logKeyChanged,
|
|
1393
1441
|
logKeyRemoved,
|
|
1394
1442
|
};
|