react-native-onyx 2.0.68 → 2.0.70
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/OnyxUtils.d.ts +6 -5
- package/dist/OnyxUtils.js +6 -5
- package/dist/useOnyx.js +6 -2
- package/package.json +1 -1
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -75,7 +75,8 @@ declare function isCollectionMemberKey<TCollectionKey extends CollectionKeyBase>
|
|
|
75
75
|
/**
|
|
76
76
|
* Splits a collection member key into the collection key part and the ID part.
|
|
77
77
|
* @param key - The collection member key to split.
|
|
78
|
-
* @returns A tuple where the first element is the collection part and the second element is the ID part
|
|
78
|
+
* @returns A tuple where the first element is the collection part and the second element is the ID part,
|
|
79
|
+
* or throws an Error if the key is not a collection one.
|
|
79
80
|
*/
|
|
80
81
|
declare function splitCollectionMemberKey<TKey extends CollectionKey, CollectionKeyType = TKey extends `${infer Prefix}_${string}` ? `${Prefix}_` : never>(key: TKey): [CollectionKeyType, string];
|
|
81
82
|
/**
|
|
@@ -86,7 +87,7 @@ declare function isKeyMatch(configKey: OnyxKey, key: OnyxKey): boolean;
|
|
|
86
87
|
/** Checks to see if this key has been flagged as safe for removal. */
|
|
87
88
|
declare function isSafeEvictionKey(testKey: OnyxKey): boolean;
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
+
* Extracts the collection identifier of a given collection member key.
|
|
90
91
|
*
|
|
91
92
|
* For example:
|
|
92
93
|
* - `getCollectionKey("report_123")` would return "report_"
|
|
@@ -94,10 +95,10 @@ declare function isSafeEvictionKey(testKey: OnyxKey): boolean;
|
|
|
94
95
|
* - `getCollectionKey("report_-1_something")` would return "report_"
|
|
95
96
|
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
96
97
|
*
|
|
97
|
-
* @param
|
|
98
|
-
* @
|
|
98
|
+
* @param key - The collection key to process.
|
|
99
|
+
* @returns The plain collection key or throws an Error if the key is not a collection one.
|
|
99
100
|
*/
|
|
100
|
-
declare function getCollectionKey(key:
|
|
101
|
+
declare function getCollectionKey(key: CollectionKey): string;
|
|
101
102
|
/**
|
|
102
103
|
* Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
103
104
|
* If the requested key is a collection, it will return an object with all the collection members.
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -332,7 +332,8 @@ function isCollectionMemberKey(collectionKey, key, collectionKeyLength) {
|
|
|
332
332
|
/**
|
|
333
333
|
* Splits a collection member key into the collection key part and the ID part.
|
|
334
334
|
* @param key - The collection member key to split.
|
|
335
|
-
* @returns A tuple where the first element is the collection part and the second element is the ID part
|
|
335
|
+
* @returns A tuple where the first element is the collection part and the second element is the ID part,
|
|
336
|
+
* or throws an Error if the key is not a collection one.
|
|
336
337
|
*/
|
|
337
338
|
function splitCollectionMemberKey(key) {
|
|
338
339
|
const collectionKey = getCollectionKey(key);
|
|
@@ -350,7 +351,7 @@ function isSafeEvictionKey(testKey) {
|
|
|
350
351
|
return evictionAllowList.some((key) => isKeyMatch(key, testKey));
|
|
351
352
|
}
|
|
352
353
|
/**
|
|
353
|
-
*
|
|
354
|
+
* Extracts the collection identifier of a given collection member key.
|
|
354
355
|
*
|
|
355
356
|
* For example:
|
|
356
357
|
* - `getCollectionKey("report_123")` would return "report_"
|
|
@@ -358,8 +359,8 @@ function isSafeEvictionKey(testKey) {
|
|
|
358
359
|
* - `getCollectionKey("report_-1_something")` would return "report_"
|
|
359
360
|
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
360
361
|
*
|
|
361
|
-
* @param
|
|
362
|
-
* @
|
|
362
|
+
* @param key - The collection key to process.
|
|
363
|
+
* @returns The plain collection key or throws an Error if the key is not a collection one.
|
|
363
364
|
*/
|
|
364
365
|
function getCollectionKey(key) {
|
|
365
366
|
// Start by finding the position of the last underscore in the string
|
|
@@ -1034,7 +1035,7 @@ function subscribeToKey(connectOptions) {
|
|
|
1034
1035
|
// Performance improvement
|
|
1035
1036
|
// If the mapping is connected to an onyx key that is not a collection
|
|
1036
1037
|
// we can skip the call to getAllKeys() and return an array with a single item
|
|
1037
|
-
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !mapping.key
|
|
1038
|
+
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && OnyxCache_1.default.getAllKeys().has(mapping.key)) {
|
|
1038
1039
|
return new Set([mapping.key]);
|
|
1039
1040
|
}
|
|
1040
1041
|
return getAllKeys();
|
package/dist/useOnyx.js
CHANGED
|
@@ -26,7 +26,7 @@ function useOnyx(key, options) {
|
|
|
26
26
|
const newValueRef = (0, react_1.useRef)(null);
|
|
27
27
|
// Stores the previously result returned by the hook, containing the data from cache and the fetch status.
|
|
28
28
|
// We initialize it to `undefined` and `loading` fetch status to simulate the initial result when the hook is loading from the cache.
|
|
29
|
-
// However, if `initWithStoredValues` is `
|
|
29
|
+
// However, if `initWithStoredValues` is `false` we set the fetch status to `loaded` since we want to signal that data is ready.
|
|
30
30
|
const resultRef = (0, react_1.useRef)([
|
|
31
31
|
undefined,
|
|
32
32
|
{
|
|
@@ -74,6 +74,10 @@ function useOnyx(key, options) {
|
|
|
74
74
|
}, [key, options === null || options === void 0 ? void 0 : options.canEvict]);
|
|
75
75
|
const getSnapshot = (0, react_1.useCallback)(() => {
|
|
76
76
|
var _a, _b, _c;
|
|
77
|
+
// We return the initial result right away during the first connection if `initWithStoredValues` is set to `false`.
|
|
78
|
+
if (isFirstConnectionRef.current && (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false) {
|
|
79
|
+
return resultRef.current;
|
|
80
|
+
}
|
|
77
81
|
// We get the value from cache while the first connection to Onyx is being made,
|
|
78
82
|
// so we can return any cached value right away. After the connection is made, we only
|
|
79
83
|
// update `newValueRef` when `Onyx.connect()` callback is fired.
|
|
@@ -123,7 +127,7 @@ function useOnyx(key, options) {
|
|
|
123
127
|
resultRef.current = [previousValueRef.current, { status: newFetchStatus !== null && newFetchStatus !== void 0 ? newFetchStatus : 'loaded' }];
|
|
124
128
|
}
|
|
125
129
|
return resultRef.current;
|
|
126
|
-
}, [key, selectorRef, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.initialValue]);
|
|
130
|
+
}, [key, selectorRef, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.initialValue]);
|
|
127
131
|
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
|
|
128
132
|
connectionRef.current = OnyxConnectionManager_1.default.connect({
|
|
129
133
|
key,
|