react-native-onyx 3.0.38 → 3.0.40
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 -8
- package/dist/OnyxCache.d.ts +1 -1
- package/dist/OnyxCache.js +1 -1
- package/dist/OnyxSnapshotCache.js +3 -6
- package/dist/OnyxUtils.d.ts +2 -2
- package/dist/OnyxUtils.js +13 -26
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -317,14 +317,7 @@ function clear(keysToPreserve = []) {
|
|
|
317
317
|
const newValue = (_a = defaultKeyStates[key]) !== null && _a !== void 0 ? _a : null;
|
|
318
318
|
if (newValue !== oldValue) {
|
|
319
319
|
OnyxCache_1.default.set(key, newValue);
|
|
320
|
-
|
|
321
|
-
try {
|
|
322
|
-
collectionKey = OnyxUtils_1.default.getCollectionKey(key);
|
|
323
|
-
}
|
|
324
|
-
catch (e) {
|
|
325
|
-
// If getCollectionKey() throws an error it means the key is not a collection key.
|
|
326
|
-
collectionKey = undefined;
|
|
327
|
-
}
|
|
320
|
+
const collectionKey = OnyxUtils_1.default.getCollectionKey(key);
|
|
328
321
|
if (collectionKey) {
|
|
329
322
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
330
323
|
keyValuesToResetAsCollection[collectionKey] = { oldValues: {}, newValues: {} };
|
package/dist/OnyxCache.d.ts
CHANGED
|
@@ -162,7 +162,7 @@ declare class OnyxCache {
|
|
|
162
162
|
/**
|
|
163
163
|
* Get the collection key for a given member key
|
|
164
164
|
*/
|
|
165
|
-
getCollectionKey(key: OnyxKey): OnyxKey |
|
|
165
|
+
getCollectionKey(key: OnyxKey): OnyxKey | undefined;
|
|
166
166
|
/**
|
|
167
167
|
* Get all data for a collection key
|
|
168
168
|
*/
|
package/dist/OnyxCache.js
CHANGED
|
@@ -100,14 +100,11 @@ class OnyxSnapshotCache {
|
|
|
100
100
|
invalidateForKey(keyToInvalidate) {
|
|
101
101
|
// Always invalidate the exact key
|
|
102
102
|
this.snapshotCache.delete(keyToInvalidate);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
// Check if the key is a collection member and invalidate the collection base key
|
|
104
|
+
const collectionBaseKey = OnyxUtils_1.default.getCollectionKey(keyToInvalidate);
|
|
105
|
+
if (collectionBaseKey) {
|
|
106
106
|
this.snapshotCache.delete(collectionBaseKey);
|
|
107
107
|
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
// do nothing - this just means the key is not a collection member
|
|
110
|
-
}
|
|
111
108
|
}
|
|
112
109
|
/**
|
|
113
110
|
* Clear all snapshot cache
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -163,9 +163,9 @@ declare function isKeyMatch(configKey: OnyxKey, key: OnyxKey): boolean;
|
|
|
163
163
|
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
164
164
|
*
|
|
165
165
|
* @param key - The collection key to process.
|
|
166
|
-
* @returns The plain collection key or
|
|
166
|
+
* @returns The plain collection key or undefined if the key is not a collection one.
|
|
167
167
|
*/
|
|
168
|
-
declare function getCollectionKey(key: CollectionKey): string;
|
|
168
|
+
declare function getCollectionKey(key: CollectionKey): string | undefined;
|
|
169
169
|
/**
|
|
170
170
|
* Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
171
171
|
* If the requested key is a collection, it will return an object with all the collection members.
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -389,15 +389,9 @@ function isCollectionMemberKey(collectionKey, key) {
|
|
|
389
389
|
* @returns true if the key is a collection member, false otherwise
|
|
390
390
|
*/
|
|
391
391
|
function isCollectionMember(key) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return key.length > collectionKey.length;
|
|
396
|
-
}
|
|
397
|
-
catch (e) {
|
|
398
|
-
// If getCollectionKey throws, the key is not a collection member
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
392
|
+
const collectionKey = getCollectionKey(key);
|
|
393
|
+
// If the key is longer than the collection key, it's a collection member
|
|
394
|
+
return !!collectionKey && key.length > collectionKey.length;
|
|
401
395
|
}
|
|
402
396
|
/**
|
|
403
397
|
* Checks if a given key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
|
|
@@ -417,14 +411,10 @@ function isCollectionMember(key) {
|
|
|
417
411
|
* @returns true if key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
|
|
418
412
|
*/
|
|
419
413
|
function isRamOnlyKey(key) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// If collectionKey exists for a given key, check if it's a RAM-only key
|
|
414
|
+
const collectionKey = getCollectionKey(key);
|
|
415
|
+
if (collectionKey) {
|
|
423
416
|
return OnyxCache_1.default.isRamOnlyKey(collectionKey);
|
|
424
417
|
}
|
|
425
|
-
catch (_a) {
|
|
426
|
-
// If getCollectionKey throws, the key is not a collection member
|
|
427
|
-
}
|
|
428
418
|
return OnyxCache_1.default.isRamOnlyKey(key);
|
|
429
419
|
}
|
|
430
420
|
/**
|
|
@@ -439,8 +429,12 @@ function splitCollectionMemberKey(key, collectionKey) {
|
|
|
439
429
|
throw new Error(`Invalid '${collectionKey}' collection key provided, it isn't compatible with '${key}' key.`);
|
|
440
430
|
}
|
|
441
431
|
if (!collectionKey) {
|
|
432
|
+
const resolvedKey = getCollectionKey(key);
|
|
433
|
+
if (!resolvedKey) {
|
|
434
|
+
throw new Error(`Invalid '${key}' key provided, only collection keys are allowed.`);
|
|
435
|
+
}
|
|
442
436
|
// eslint-disable-next-line no-param-reassign
|
|
443
|
-
collectionKey =
|
|
437
|
+
collectionKey = resolvedKey;
|
|
444
438
|
}
|
|
445
439
|
return [collectionKey, key.slice(collectionKey.length)];
|
|
446
440
|
}
|
|
@@ -461,7 +455,7 @@ function isKeyMatch(configKey, key) {
|
|
|
461
455
|
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
462
456
|
*
|
|
463
457
|
* @param key - The collection key to process.
|
|
464
|
-
* @returns The plain collection key or
|
|
458
|
+
* @returns The plain collection key or undefined if the key is not a collection one.
|
|
465
459
|
*/
|
|
466
460
|
function getCollectionKey(key) {
|
|
467
461
|
// Start by finding the position of the last underscore in the string
|
|
@@ -477,7 +471,7 @@ function getCollectionKey(key) {
|
|
|
477
471
|
// Move to the next underscore to check smaller possible keys
|
|
478
472
|
lastUnderscoreIndex = key.lastIndexOf('_', lastUnderscoreIndex - 1);
|
|
479
473
|
}
|
|
480
|
-
|
|
474
|
+
return undefined;
|
|
481
475
|
}
|
|
482
476
|
/**
|
|
483
477
|
* Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
@@ -625,14 +619,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
|
|
|
625
619
|
// do the same in keysChanged, because we only call that function when a collection key changes, and it doesn't happen that often.
|
|
626
620
|
// For performance reason, we look for the given key and later if don't find it we look for the collection key, instead of checking if it is a collection key first.
|
|
627
621
|
let stateMappingKeys = (_a = onyxKeyToSubscriptionIDs.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
628
|
-
|
|
629
|
-
try {
|
|
630
|
-
collectionKey = getCollectionKey(key);
|
|
631
|
-
}
|
|
632
|
-
catch (e) {
|
|
633
|
-
// If getCollectionKey() throws an error it means the key is not a collection key.
|
|
634
|
-
collectionKey = undefined;
|
|
635
|
-
}
|
|
622
|
+
const collectionKey = getCollectionKey(key);
|
|
636
623
|
if (collectionKey) {
|
|
637
624
|
// Getting the collection key from the specific key because only collection keys were stored in the mapping.
|
|
638
625
|
stateMappingKeys = [...stateMappingKeys, ...((_b = onyxKeyToSubscriptionIDs.get(collectionKey)) !== null && _b !== void 0 ? _b : [])];
|