react-native-onyx 3.0.78 → 3.0.80
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.
|
@@ -42,7 +42,7 @@ declare class OnyxSnapshotCache {
|
|
|
42
42
|
* Other options like `reuseConnection` don't affect the data transformation
|
|
43
43
|
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
|
|
44
44
|
*/
|
|
45
|
-
registerConsumer<TKey extends OnyxKey, TReturnValue>(options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector'>): string;
|
|
45
|
+
registerConsumer<TKey extends OnyxKey, TReturnValue>(key: TKey, options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector'>): string;
|
|
46
46
|
/**
|
|
47
47
|
* Deregister a consumer for a cache key.
|
|
48
48
|
* Decrements reference counter and removes cache entry if no consumers remain.
|
|
@@ -39,9 +39,9 @@ class OnyxSnapshotCache {
|
|
|
39
39
|
* Other options like `reuseConnection` don't affect the data transformation
|
|
40
40
|
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
|
|
41
41
|
*/
|
|
42
|
-
registerConsumer(options) {
|
|
42
|
+
registerConsumer(key, options) {
|
|
43
43
|
const selectorID = (options === null || options === void 0 ? void 0 : options.selector) ? this.getSelectorID(options.selector) : 'no_selector';
|
|
44
|
-
const cacheKey =
|
|
44
|
+
const cacheKey = `${key}_${selectorID}`;
|
|
45
45
|
// Increment reference count for this cache key
|
|
46
46
|
const currentCount = this.cacheKeyRefCounts.get(cacheKey) || 0;
|
|
47
47
|
this.cacheKeyRefCounts.set(cacheKey, currentCount + 1);
|
package/dist/useOnyx.js
CHANGED
|
@@ -107,9 +107,9 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
107
107
|
// Inside useOnyx.ts, we need to track the sourceValue separately
|
|
108
108
|
const sourceValueRef = (0, react_1.useRef)(undefined);
|
|
109
109
|
// Cache the options key to avoid regenerating it every getSnapshot call
|
|
110
|
-
const cacheKey = (0, react_1.useMemo)(() => OnyxSnapshotCache_1.default.registerConsumer({
|
|
110
|
+
const cacheKey = (0, react_1.useMemo)(() => OnyxSnapshotCache_1.default.registerConsumer(key, {
|
|
111
111
|
selector: options === null || options === void 0 ? void 0 : options.selector,
|
|
112
|
-
}), [options === null || options === void 0 ? void 0 : options.selector]);
|
|
112
|
+
}), [key, options === null || options === void 0 ? void 0 : options.selector]);
|
|
113
113
|
(0, react_1.useEffect)(() => () => OnyxSnapshotCache_1.default.deregisterConsumer(key, cacheKey), [key, cacheKey]);
|
|
114
114
|
// Track previous dependencies to prevent infinite loops
|
|
115
115
|
const previousDependenciesRef = (0, react_1.useRef)([]);
|