react-native-onyx 3.0.106 → 3.0.108
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 +1 -1
- package/dist/OnyxConnectionManager.js +1 -1
- package/dist/OnyxSnapshotCache.js +15 -9
- package/dist/OnyxUtils.js +6 -3
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -281,7 +281,7 @@ function merge(key, changes) {
|
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
catch (error) {
|
|
284
|
-
Logger.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
|
|
284
|
+
Logger.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error instanceof Error ? error.toString() : String(error)}`);
|
|
285
285
|
return Promise.resolve();
|
|
286
286
|
}
|
|
287
287
|
});
|
|
@@ -90,7 +90,7 @@ class OnyxConnectionManager {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
catch (error) {
|
|
93
|
-
Logger.logAlert(`[ConnectionManager] Subscriber callback threw an error for key '${connection.onyxKey}': ${error}`);
|
|
93
|
+
Logger.logAlert(`[ConnectionManager] Subscriber callback threw an error for key '${connection.onyxKey}': ${String(error)}`);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -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
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -68,6 +68,9 @@ let lastDiskPressureLogTime = 0;
|
|
|
68
68
|
function resetDiskPressureLogThrottle() {
|
|
69
69
|
lastDiskPressureLogTime = 0;
|
|
70
70
|
}
|
|
71
|
+
function formatCaughtError(error) {
|
|
72
|
+
return error instanceof Error ? error.toString() : String(error);
|
|
73
|
+
}
|
|
71
74
|
// Key/value store of Onyx key and arrays of values to merge
|
|
72
75
|
let mergeQueue = {};
|
|
73
76
|
let mergeQueuePromise = {};
|
|
@@ -494,7 +497,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
494
497
|
subscriber.callback(cachedCollection, subscriber.key);
|
|
495
498
|
}
|
|
496
499
|
catch (error) {
|
|
497
|
-
Logger.logAlert(`[OnyxUtils.keysChanged] Subscriber callback threw an error for key '${collectionKey}': ${error}`);
|
|
500
|
+
Logger.logAlert(`[OnyxUtils.keysChanged] Subscriber callback threw an error for key '${collectionKey}': ${formatCaughtError(error)}`);
|
|
498
501
|
}
|
|
499
502
|
}
|
|
500
503
|
// Notify member-level subscribers (e.g. subscribed to `report_123`)
|
|
@@ -515,7 +518,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
515
518
|
});
|
|
516
519
|
}
|
|
517
520
|
catch (error) {
|
|
518
|
-
Logger.logAlert(`[OnyxUtils.keysChanged] Subscriber callback threw an error for key '${collectionKey}': ${error}`);
|
|
521
|
+
Logger.logAlert(`[OnyxUtils.keysChanged] Subscriber callback threw an error for key '${collectionKey}': ${formatCaughtError(error)}`);
|
|
519
522
|
}
|
|
520
523
|
}
|
|
521
524
|
}
|
|
@@ -582,7 +585,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true) {
|
|
|
582
585
|
continue;
|
|
583
586
|
}
|
|
584
587
|
catch (error) {
|
|
585
|
-
Logger.logAlert(`[OnyxUtils.keyChanged] Subscriber callback threw an error for key '${key}': ${error}`);
|
|
588
|
+
Logger.logAlert(`[OnyxUtils.keyChanged] Subscriber callback threw an error for key '${key}': ${formatCaughtError(error)}`);
|
|
586
589
|
}
|
|
587
590
|
continue;
|
|
588
591
|
}
|