react-native-onyx 3.0.147 → 3.0.149
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 -2
- package/dist/OnyxCache.d.ts +8 -0
- package/dist/OnyxCache.js +19 -4
- package/dist/OnyxSubscriptionManager.js +1 -1
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -74,7 +74,11 @@ function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], shouldSync
|
|
|
74
74
|
const isCollectionMember = !!collectionKey && OnyxKeys_1.default.isCollectionMemberKey(collectionKey, key);
|
|
75
75
|
// Capture the previous cached value before cache.set() so notifyCollection() can diff old vs new per member.
|
|
76
76
|
const previousValue = isCollectionMember ? OnyxCache_1.default.get(key) : undefined;
|
|
77
|
+
// The key stays indexed because this answer can predate a write of ours still on its way to storage, and only indexed keys get deleted by Onyx.clear and collection sweeps.
|
|
77
78
|
OnyxCache_1.default.set(key, value);
|
|
79
|
+
if (value === null || value === undefined) {
|
|
80
|
+
OnyxCache_1.default.addRemovedInOtherInstanceKey(key);
|
|
81
|
+
}
|
|
78
82
|
if (isCollectionMember && collectionKey) {
|
|
79
83
|
let batch = collectionBatches.get(collectionKey);
|
|
80
84
|
if (!batch) {
|
|
@@ -697,7 +701,7 @@ function exportState() {
|
|
|
697
701
|
* @returns The current value, or `undefined` if the key has none.
|
|
698
702
|
*/
|
|
699
703
|
function get(key) {
|
|
700
|
-
return OnyxUtils_1.default.afterInit(() =>
|
|
704
|
+
return OnyxUtils_1.default.afterInit(() => Promise.resolve(OnyxSubscriptionManager_1.default.getState(key)));
|
|
701
705
|
}
|
|
702
706
|
/**
|
|
703
707
|
* Reads several Onyx keys at once, without subscribing. Use `useOnyx()` or `Onyx.connectWithoutView()` when
|
|
@@ -718,7 +722,7 @@ function get(key) {
|
|
|
718
722
|
*/
|
|
719
723
|
function multiGet(keys) {
|
|
720
724
|
// map() widens the key tuple to an array, so the per-slot value types survive only through the cast.
|
|
721
|
-
return OnyxUtils_1.default.afterInit(() => Promise.resolve(keys.map((key) =>
|
|
725
|
+
return OnyxUtils_1.default.afterInit(() => Promise.resolve(keys.map((key) => OnyxSubscriptionManager_1.default.getState(key))));
|
|
722
726
|
}
|
|
723
727
|
const Onyx = {
|
|
724
728
|
METHOD: OnyxUtils_1.default.METHOD,
|
package/dist/OnyxCache.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ declare class OnyxCache {
|
|
|
15
15
|
private storageKeys;
|
|
16
16
|
/** A list of keys where a nullish value has been fetched from storage before, but the key still exists in cache */
|
|
17
17
|
private nullishStorageKeys;
|
|
18
|
+
/** Keys another instance removed, which explains why the cache has no value for them. They still count as uncached, unlike nullish keys. */
|
|
19
|
+
private removedInOtherInstanceKeys;
|
|
18
20
|
/** A map of cached values */
|
|
19
21
|
private storageMap;
|
|
20
22
|
/**
|
|
@@ -55,6 +57,12 @@ declare class OnyxCache {
|
|
|
55
57
|
hasNullishStorageKey(key: OnyxKey): boolean;
|
|
56
58
|
/** Used to clear keys that are null/undefined in cache */
|
|
57
59
|
clearNullishStorageKeys(): void;
|
|
60
|
+
/** Records that another instance removed this key */
|
|
61
|
+
addRemovedInOtherInstanceKey(key: OnyxKey): void;
|
|
62
|
+
/** Whether another instance removed this key and it hasn't changed here since */
|
|
63
|
+
hasRemovedInOtherInstanceKey(key: OnyxKey): boolean;
|
|
64
|
+
/** A write here replaces what the cache knew about the key being empty, including another instance's removal */
|
|
65
|
+
private forgetEmptyMarks;
|
|
58
66
|
/** Check whether cache has data for the given key */
|
|
59
67
|
hasCacheForKey(key: OnyxKey): boolean;
|
|
60
68
|
/** Get a cached value from storage */
|
package/dist/OnyxCache.js
CHANGED
|
@@ -44,12 +44,13 @@ class OnyxCache {
|
|
|
44
44
|
this.recentlyAccessedKeys = new Set();
|
|
45
45
|
this.storageKeys = new Set();
|
|
46
46
|
this.nullishStorageKeys = new Set();
|
|
47
|
+
this.removedInOtherInstanceKeys = new Set();
|
|
47
48
|
this.storageMap = {};
|
|
48
49
|
this.pendingPromises = new Map();
|
|
49
50
|
this.collectionSnapshots = new Map();
|
|
50
51
|
this.dirtyCollections = new Set();
|
|
51
52
|
// bind all public methods to prevent problems with `this`
|
|
52
|
-
(0, lodash_bindall_1.default)(this, 'getAllKeys', 'get', 'hasCacheForKey', 'addKey', 'addNullishStorageKey', 'hasNullishStorageKey', 'clearNullishStorageKeys', 'set', 'drop', 'merge', 'hydrate', 'hasPendingTask', 'getTaskPromise', 'captureTask', 'setAllKeys', 'setEvictionAllowList', 'isEvictableKey', 'removeLastAccessedKey', 'addLastAccessedKey', 'addEvictableKeysToRecentlyAccessedList', 'getKeyForEviction', 'setCollectionKeys', 'hasValueChanged', 'getCollectionData');
|
|
53
|
+
(0, lodash_bindall_1.default)(this, 'getAllKeys', 'get', 'hasCacheForKey', 'addKey', 'addNullishStorageKey', 'hasNullishStorageKey', 'clearNullishStorageKeys', 'addRemovedInOtherInstanceKey', 'hasRemovedInOtherInstanceKey', 'set', 'drop', 'merge', 'hydrate', 'hasPendingTask', 'getTaskPromise', 'captureTask', 'setAllKeys', 'setEvictionAllowList', 'isEvictableKey', 'removeLastAccessedKey', 'addLastAccessedKey', 'addEvictableKeysToRecentlyAccessedList', 'getKeyForEviction', 'setCollectionKeys', 'hasValueChanged', 'getCollectionData');
|
|
53
54
|
}
|
|
54
55
|
/** Get all the storage keys */
|
|
55
56
|
getAllKeys() {
|
|
@@ -91,6 +92,19 @@ class OnyxCache {
|
|
|
91
92
|
clearNullishStorageKeys() {
|
|
92
93
|
this.nullishStorageKeys = new Set();
|
|
93
94
|
}
|
|
95
|
+
/** Records that another instance removed this key */
|
|
96
|
+
addRemovedInOtherInstanceKey(key) {
|
|
97
|
+
this.removedInOtherInstanceKeys.add(key);
|
|
98
|
+
}
|
|
99
|
+
/** Whether another instance removed this key and it hasn't changed here since */
|
|
100
|
+
hasRemovedInOtherInstanceKey(key) {
|
|
101
|
+
return this.removedInOtherInstanceKeys.has(key);
|
|
102
|
+
}
|
|
103
|
+
/** A write here replaces what the cache knew about the key being empty, including another instance's removal */
|
|
104
|
+
forgetEmptyMarks(key) {
|
|
105
|
+
this.nullishStorageKeys.delete(key);
|
|
106
|
+
this.removedInOtherInstanceKeys.delete(key);
|
|
107
|
+
}
|
|
94
108
|
/** Check whether cache has data for the given key */
|
|
95
109
|
hasCacheForKey(key) {
|
|
96
110
|
return this.storageMap[key] !== undefined || this.hasNullishStorageKey(key);
|
|
@@ -107,7 +121,7 @@ class OnyxCache {
|
|
|
107
121
|
this.addKey(key);
|
|
108
122
|
// When a key is explicitly set in cache, we can remove it from the list of nullish keys,
|
|
109
123
|
// since it will either be set to a non nullish value or removed from the cache completely.
|
|
110
|
-
this.
|
|
124
|
+
this.forgetEmptyMarks(key);
|
|
111
125
|
const collectionKey = OnyxKeys_1.default.getCollectionKey(key);
|
|
112
126
|
const oldValue = this.storageMap[key];
|
|
113
127
|
if (value === null || value === undefined) {
|
|
@@ -135,6 +149,7 @@ class OnyxCache {
|
|
|
135
149
|
this.collectionSnapshots.delete(key);
|
|
136
150
|
}
|
|
137
151
|
this.storageKeys.delete(key);
|
|
152
|
+
this.removedInOtherInstanceKeys.delete(key);
|
|
138
153
|
OnyxKeys_1.default.deregisterMemberKey(key);
|
|
139
154
|
}
|
|
140
155
|
/**
|
|
@@ -167,7 +182,7 @@ class OnyxCache {
|
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
else {
|
|
170
|
-
this.
|
|
185
|
+
this.forgetEmptyMarks(key);
|
|
171
186
|
const existing = this.storageMap[key];
|
|
172
187
|
if (existing !== undefined) {
|
|
173
188
|
// Key already has a value, so the empty-cache assumption doesn't hold here (e.g. a write
|
|
@@ -228,7 +243,7 @@ class OnyxCache {
|
|
|
228
243
|
}
|
|
229
244
|
}
|
|
230
245
|
else {
|
|
231
|
-
this.
|
|
246
|
+
this.forgetEmptyMarks(key);
|
|
232
247
|
// Per-key merge instead of spreading the entire storageMap
|
|
233
248
|
const existing = this.storageMap[key];
|
|
234
249
|
const merged = utils_1.default.fastMerge(existing, value, CACHE_MERGE_OPTIONS).result;
|
|
@@ -43,7 +43,7 @@ const storage_1 = __importDefault(require("./storage"));
|
|
|
43
43
|
const reportedCacheMisses = new Set();
|
|
44
44
|
function reportCacheMissIfStorageHasValue(key) {
|
|
45
45
|
var _a;
|
|
46
|
-
if (OnyxKeys_1.default.isRamOnlyKey(key) ||
|
|
46
|
+
if (!OnyxCache_1.default.getAllKeys().has(key) || OnyxKeys_1.default.isRamOnlyKey(key) || OnyxCache_1.default.hasNullishStorageKey(key) || OnyxCache_1.default.hasRemovedInOtherInstanceKey(key)) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
const reportKey = (_a = OnyxKeys_1.default.getCollectionKey(key)) !== null && _a !== void 0 ? _a : key;
|