react-native-onyx 3.0.77 → 3.0.79
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/OnyxUtils.js +29 -23
- package/package.json +1 -1
package/dist/OnyxUtils.js
CHANGED
|
@@ -1336,33 +1336,39 @@ function mergeCollectionWithPatches({ collectionKey, collection, mergeReplaceNul
|
|
|
1336
1336
|
// We can safely remove nested null values when using (multi-)set,
|
|
1337
1337
|
// because we will simply overwrite the existing values in storage.
|
|
1338
1338
|
const keyValuePairsForNewCollection = prepareKeyValuePairsForStorage(newCollection, true);
|
|
1339
|
-
const promises = [];
|
|
1340
|
-
// We need to get the previously existing values so we can compare the new ones
|
|
1341
|
-
// against them, to avoid unnecessary subscriber updates.
|
|
1342
|
-
const previousCollectionPromise = Promise.all(existingKeys.map((key) => get(key).then((value) => [key, value]))).then(Object.fromEntries);
|
|
1343
|
-
// New keys will be added via multiSet while existing keys will be updated using multiMerge
|
|
1344
|
-
// This is because setting a key that doesn't exist yet with multiMerge will throw errors
|
|
1345
|
-
// We can skip this step for RAM-only keys as they should never be saved to storage
|
|
1346
|
-
if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForExistingCollection.length > 0) {
|
|
1347
|
-
promises.push(storage_1.default.multiMerge(keyValuePairsForExistingCollection));
|
|
1348
|
-
}
|
|
1349
|
-
// We can skip this step for RAM-only keys as they should never be saved to storage
|
|
1350
|
-
if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForNewCollection.length > 0) {
|
|
1351
|
-
promises.push(storage_1.default.multiSet(keyValuePairsForNewCollection));
|
|
1352
|
-
}
|
|
1353
1339
|
// finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
|
|
1354
1340
|
const finalMergedCollection = Object.assign(Object.assign({}, existingKeyCollection), newCollection);
|
|
1355
|
-
//
|
|
1356
|
-
// and
|
|
1357
|
-
|
|
1341
|
+
// Pre-warm cache for any existing storage keys that aren't yet in cache. get() is a no-op
|
|
1342
|
+
// (sync-resolved) for cache hits, and on a cache miss it reads from storage and writes the
|
|
1343
|
+
// value back to cache. This is required so the subsequent cache.merge() merges the new delta
|
|
1344
|
+
// into the real previous storage value (rather than starting from `undefined` and dropping
|
|
1345
|
+
// the existing keys).
|
|
1346
|
+
return Promise.all(existingKeys.map((key) => get(key))).then(() => {
|
|
1347
|
+
// Snapshot previous values from the (now-warm) cache for keysChanged's diff, then update
|
|
1348
|
+
// cache and notify subscribers synchronously BEFORE issuing storage writes. This matches
|
|
1349
|
+
// the cache-first / storage-second invariant followed by every other Onyx write method
|
|
1350
|
+
// (setWithRetry, applyMerge, setCollectionWithRetry, partialSetCollection, clear),
|
|
1351
|
+
// ensuring subscribers still reflect the merged data even if the subsequent storage
|
|
1352
|
+
// write fails.
|
|
1353
|
+
const previousCollection = getCachedCollection(collectionKey, existingKeys);
|
|
1358
1354
|
OnyxCache_1.default.merge(finalMergedCollection);
|
|
1359
1355
|
keysChanged(collectionKey, finalMergedCollection, previousCollection);
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1356
|
+
const promises = [];
|
|
1357
|
+
// New keys will be added via multiSet while existing keys will be updated using multiMerge
|
|
1358
|
+
// This is because setting a key that doesn't exist yet with multiMerge will throw errors
|
|
1359
|
+
// We can skip this step for RAM-only keys as they should never be saved to storage
|
|
1360
|
+
if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForExistingCollection.length > 0) {
|
|
1361
|
+
promises.push(storage_1.default.multiMerge(keyValuePairsForExistingCollection));
|
|
1362
|
+
}
|
|
1363
|
+
// We can skip this step for RAM-only keys as they should never be saved to storage
|
|
1364
|
+
if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForNewCollection.length > 0) {
|
|
1365
|
+
promises.push(storage_1.default.multiSet(keyValuePairsForNewCollection));
|
|
1366
|
+
}
|
|
1367
|
+
return Promise.all(promises)
|
|
1368
|
+
.catch((error) => retryOperation(error, mergeCollectionWithPatches, { collectionKey, collection: resultCollection, mergeReplaceNullPatches, isProcessingCollectionUpdate }, retryAttempt))
|
|
1369
|
+
.then(() => {
|
|
1370
|
+
sendActionToDevTools(METHOD.MERGE_COLLECTION, undefined, resultCollection);
|
|
1371
|
+
});
|
|
1366
1372
|
});
|
|
1367
1373
|
})
|
|
1368
1374
|
.then(() => undefined);
|