react-native-onyx 3.0.31 → 3.0.32
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 +7 -4
- package/dist/useOnyx.js +1 -1
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -289,8 +289,10 @@ function clear(keysToPreserve = []) {
|
|
|
289
289
|
var _a;
|
|
290
290
|
OnyxCache_1.default.clearNullishStorageKeys();
|
|
291
291
|
const keysToBeClearedFromStorage = [];
|
|
292
|
-
const keyValuesToResetAsCollection = {};
|
|
293
292
|
const keyValuesToResetIndividually = {};
|
|
293
|
+
// We need to store old and new values for collection keys to properly notify subscribers when clearing Onyx
|
|
294
|
+
// because the notification process needs the old values in cache but at that point they will be already removed from it.
|
|
295
|
+
const keyValuesToResetAsCollection = {};
|
|
294
296
|
const allKeys = new Set([...cachedKeys, ...initialKeys]);
|
|
295
297
|
// The only keys that should not be cleared are:
|
|
296
298
|
// 1. Anything specifically passed in keysToPreserve (because some keys like language preferences, offline
|
|
@@ -320,9 +322,10 @@ function clear(keysToPreserve = []) {
|
|
|
320
322
|
}
|
|
321
323
|
if (collectionKey) {
|
|
322
324
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
323
|
-
keyValuesToResetAsCollection[collectionKey] = {};
|
|
325
|
+
keyValuesToResetAsCollection[collectionKey] = { oldValues: {}, newValues: {} };
|
|
324
326
|
}
|
|
325
|
-
keyValuesToResetAsCollection[collectionKey][key] =
|
|
327
|
+
keyValuesToResetAsCollection[collectionKey].oldValues[key] = oldValue;
|
|
328
|
+
keyValuesToResetAsCollection[collectionKey].newValues[key] = newValue !== null && newValue !== void 0 ? newValue : undefined;
|
|
326
329
|
}
|
|
327
330
|
else {
|
|
328
331
|
keyValuesToResetIndividually[key] = newValue !== null && newValue !== void 0 ? newValue : undefined;
|
|
@@ -341,7 +344,7 @@ function clear(keysToPreserve = []) {
|
|
|
341
344
|
updatePromises.push(OnyxUtils_1.default.scheduleSubscriberUpdate(key, value));
|
|
342
345
|
}
|
|
343
346
|
for (const [key, value] of Object.entries(keyValuesToResetAsCollection)) {
|
|
344
|
-
updatePromises.push(OnyxUtils_1.default.scheduleNotifyCollectionSubscribers(key, value));
|
|
347
|
+
updatePromises.push(OnyxUtils_1.default.scheduleNotifyCollectionSubscribers(key, value.newValues, value.oldValues));
|
|
345
348
|
}
|
|
346
349
|
const defaultKeyValuePairs = Object.entries(Object.keys(defaultKeyStates)
|
|
347
350
|
.filter((key) => !keysToPreserve.includes(key))
|
package/dist/useOnyx.js
CHANGED
|
@@ -254,7 +254,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
254
254
|
OnyxSnapshotCache_1.default.setCachedResult(key, cacheKey, resultRef.current);
|
|
255
255
|
}
|
|
256
256
|
return resultRef.current;
|
|
257
|
-
}, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, memoizedSelector, cacheKey]);
|
|
257
|
+
}, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, memoizedSelector, cacheKey, previousKey]);
|
|
258
258
|
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
|
|
259
259
|
isConnectingRef.current = true;
|
|
260
260
|
onStoreChangeFnRef.current = onStoreChange;
|