react-native-onyx 3.0.106 → 3.0.107
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/OnyxSnapshotCache.js +15 -9
- package/package.json +1 -1
|
@@ -21,11 +21,13 @@ class OnyxSnapshotCache {
|
|
|
21
21
|
*/
|
|
22
22
|
getSelectorID(selector) {
|
|
23
23
|
const typedSelector = selector;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const existingID = this.selectorIDMap.get(typedSelector);
|
|
25
|
+
if (existingID !== undefined) {
|
|
26
|
+
return existingID;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const id = this.selectorIDCounter++;
|
|
29
|
+
this.selectorIDMap.set(typedSelector, id);
|
|
30
|
+
return id;
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
31
33
|
* Register a consumer for a cache key and return the cache key.
|
|
@@ -40,10 +42,11 @@ class OnyxSnapshotCache {
|
|
|
40
42
|
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
|
|
41
43
|
*/
|
|
42
44
|
registerConsumer(key, options) {
|
|
45
|
+
var _a;
|
|
43
46
|
const selectorID = (options === null || options === void 0 ? void 0 : options.selector) ? this.getSelectorID(options.selector) : 'no_selector';
|
|
44
47
|
const cacheKey = `${key}_${selectorID}`;
|
|
45
48
|
// Increment reference count for this cache key
|
|
46
|
-
const currentCount = this.cacheKeyRefCounts.get(cacheKey)
|
|
49
|
+
const currentCount = (_a = this.cacheKeyRefCounts.get(cacheKey)) !== null && _a !== void 0 ? _a : 0;
|
|
47
50
|
this.cacheKeyRefCounts.set(cacheKey, currentCount + 1);
|
|
48
51
|
return cacheKey;
|
|
49
52
|
}
|
|
@@ -52,7 +55,8 @@ class OnyxSnapshotCache {
|
|
|
52
55
|
* Decrements reference counter and removes cache entry if no consumers remain.
|
|
53
56
|
*/
|
|
54
57
|
deregisterConsumer(key, cacheKey) {
|
|
55
|
-
|
|
58
|
+
var _a;
|
|
59
|
+
const currentCount = (_a = this.cacheKeyRefCounts.get(cacheKey)) !== null && _a !== void 0 ? _a : 0;
|
|
56
60
|
if (currentCount <= 1) {
|
|
57
61
|
// Last consumer - remove from reference counter and cache
|
|
58
62
|
this.cacheKeyRefCounts.delete(cacheKey);
|
|
@@ -82,10 +86,12 @@ class OnyxSnapshotCache {
|
|
|
82
86
|
* Set cached snapshot result for a key and cache key combination
|
|
83
87
|
*/
|
|
84
88
|
setCachedResult(key, cacheKey, result) {
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
let keyCache = this.snapshotCache.get(key);
|
|
90
|
+
if (!keyCache) {
|
|
91
|
+
keyCache = new Map();
|
|
92
|
+
this.snapshotCache.set(key, keyCache);
|
|
87
93
|
}
|
|
88
|
-
|
|
94
|
+
keyCache.set(cacheKey, result);
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* Selective cache invalidation to prevent data unavailability
|