react-native-onyx 2.0.58 → 2.0.59
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 +6 -4
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -482,21 +482,24 @@ function mergeCollection(collectionKey, collection) {
|
|
|
482
482
|
* @param keysToPreserve is a list of ONYXKEYS that should not be cleared with the rest of the data
|
|
483
483
|
*/
|
|
484
484
|
function clear(keysToPreserve = []) {
|
|
485
|
+
const defaultKeyStates = OnyxUtils_1.default.getDefaultKeyStates();
|
|
486
|
+
const initialKeys = Object.keys(defaultKeyStates);
|
|
485
487
|
return OnyxUtils_1.default.getAllKeys()
|
|
486
|
-
.then((
|
|
488
|
+
.then((cachedKeys) => {
|
|
487
489
|
OnyxCache_1.default.clearNullishStorageKeys();
|
|
488
490
|
const keysToBeClearedFromStorage = [];
|
|
489
491
|
const keyValuesToResetAsCollection = {};
|
|
490
492
|
const keyValuesToResetIndividually = {};
|
|
493
|
+
const allKeys = new Set([...cachedKeys, ...initialKeys]);
|
|
491
494
|
// The only keys that should not be cleared are:
|
|
492
495
|
// 1. Anything specifically passed in keysToPreserve (because some keys like language preferences, offline
|
|
493
496
|
// status, or activeClients need to remain in Onyx even when signed out)
|
|
494
497
|
// 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them
|
|
495
498
|
// to null would cause unknown behavior)
|
|
496
|
-
|
|
499
|
+
// 2.1 However, if a default key was explicitly set to null, we need to reset it to the default value
|
|
500
|
+
allKeys.forEach((key) => {
|
|
497
501
|
var _a;
|
|
498
502
|
const isKeyToPreserve = keysToPreserve.includes(key);
|
|
499
|
-
const defaultKeyStates = OnyxUtils_1.default.getDefaultKeyStates();
|
|
500
503
|
const isDefaultKey = key in defaultKeyStates;
|
|
501
504
|
// If the key is being removed or reset to default:
|
|
502
505
|
// 1. Update it in the cache
|
|
@@ -533,7 +536,6 @@ function clear(keysToPreserve = []) {
|
|
|
533
536
|
Object.entries(keyValuesToResetAsCollection).forEach(([key, value]) => {
|
|
534
537
|
updatePromises.push(OnyxUtils_1.default.scheduleNotifyCollectionSubscribers(key, value));
|
|
535
538
|
});
|
|
536
|
-
const defaultKeyStates = OnyxUtils_1.default.getDefaultKeyStates();
|
|
537
539
|
const defaultKeyValuePairs = Object.entries(Object.keys(defaultKeyStates)
|
|
538
540
|
.filter((key) => !keysToPreserve.includes(key))
|
|
539
541
|
.reduce((obj, key) => {
|