react-native-onyx 2.0.67 → 2.0.68
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 +9 -2
- package/dist/OnyxUtils.d.ts +3 -2
- package/dist/OnyxUtils.js +28 -17
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -416,8 +416,15 @@ function clear(keysToPreserve = []) {
|
|
|
416
416
|
const newValue = (_a = defaultKeyStates[key]) !== null && _a !== void 0 ? _a : null;
|
|
417
417
|
if (newValue !== oldValue) {
|
|
418
418
|
OnyxCache_1.default.set(key, newValue);
|
|
419
|
-
|
|
420
|
-
|
|
419
|
+
let collectionKey;
|
|
420
|
+
try {
|
|
421
|
+
collectionKey = OnyxUtils_1.default.getCollectionKey(key);
|
|
422
|
+
}
|
|
423
|
+
catch (e) {
|
|
424
|
+
// If getCollectionKey() throws an error it means the key is not a collection key.
|
|
425
|
+
collectionKey = undefined;
|
|
426
|
+
}
|
|
427
|
+
if (collectionKey) {
|
|
421
428
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
422
429
|
keyValuesToResetAsCollection[collectionKey] = {};
|
|
423
430
|
}
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -90,11 +90,12 @@ declare function isSafeEvictionKey(testKey: OnyxKey): boolean;
|
|
|
90
90
|
*
|
|
91
91
|
* For example:
|
|
92
92
|
* - `getCollectionKey("report_123")` would return "report_"
|
|
93
|
-
* - `getCollectionKey("report")` would return "report"
|
|
94
93
|
* - `getCollectionKey("report_")` would return "report_"
|
|
94
|
+
* - `getCollectionKey("report_-1_something")` would return "report_"
|
|
95
|
+
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
95
96
|
*
|
|
96
97
|
* @param {OnyxKey} key - The key to process.
|
|
97
|
-
* @return {string} The
|
|
98
|
+
* @return {string} The plain collection key.
|
|
98
99
|
*/
|
|
99
100
|
declare function getCollectionKey(key: OnyxKey): string;
|
|
100
101
|
/**
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -335,13 +335,8 @@ function isCollectionMemberKey(collectionKey, key, collectionKeyLength) {
|
|
|
335
335
|
* @returns A tuple where the first element is the collection part and the second element is the ID part.
|
|
336
336
|
*/
|
|
337
337
|
function splitCollectionMemberKey(key) {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
throw new Error(`Invalid ${key} key provided, only collection keys are allowed.`);
|
|
341
|
-
}
|
|
342
|
-
const collectionKey = key.substring(0, underscoreIndex + 1);
|
|
343
|
-
const memberKey = key.substring(underscoreIndex + 1);
|
|
344
|
-
return [collectionKey, memberKey];
|
|
338
|
+
const collectionKey = getCollectionKey(key);
|
|
339
|
+
return [collectionKey, key.slice(collectionKey.length)];
|
|
345
340
|
}
|
|
346
341
|
/**
|
|
347
342
|
* Checks to see if a provided key is the exact configured key of our connected subscriber
|
|
@@ -359,18 +354,28 @@ function isSafeEvictionKey(testKey) {
|
|
|
359
354
|
*
|
|
360
355
|
* For example:
|
|
361
356
|
* - `getCollectionKey("report_123")` would return "report_"
|
|
362
|
-
* - `getCollectionKey("report")` would return "report"
|
|
363
357
|
* - `getCollectionKey("report_")` would return "report_"
|
|
358
|
+
* - `getCollectionKey("report_-1_something")` would return "report_"
|
|
359
|
+
* - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
|
|
364
360
|
*
|
|
365
361
|
* @param {OnyxKey} key - The key to process.
|
|
366
|
-
* @return {string} The
|
|
362
|
+
* @return {string} The plain collection key.
|
|
367
363
|
*/
|
|
368
364
|
function getCollectionKey(key) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
365
|
+
// Start by finding the position of the last underscore in the string
|
|
366
|
+
let lastUnderscoreIndex = key.lastIndexOf('_');
|
|
367
|
+
// Iterate backwards to find the longest key that ends with '_'
|
|
368
|
+
while (lastUnderscoreIndex > 0) {
|
|
369
|
+
const possibleKey = key.slice(0, lastUnderscoreIndex + 1);
|
|
370
|
+
// Check if the substring is a key in the Set
|
|
371
|
+
if (isCollectionKey(possibleKey)) {
|
|
372
|
+
// Return the matching key and the rest of the string
|
|
373
|
+
return possibleKey;
|
|
374
|
+
}
|
|
375
|
+
// Move to the next underscore to check smaller possible keys
|
|
376
|
+
lastUnderscoreIndex = key.lastIndexOf('_', lastUnderscoreIndex - 1);
|
|
372
377
|
}
|
|
373
|
-
|
|
378
|
+
throw new Error(`Invalid '${key}' key provided, only collection keys are allowed.`);
|
|
374
379
|
}
|
|
375
380
|
/**
|
|
376
381
|
* Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
@@ -639,11 +644,17 @@ function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true,
|
|
|
639
644
|
// do the same in keysChanged, because we only call that function when a collection key changes, and it doesn't happen that often.
|
|
640
645
|
// 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.
|
|
641
646
|
let stateMappingKeys = (_a = onyxKeyToSubscriptionIDs.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
647
|
+
let collectionKey;
|
|
648
|
+
try {
|
|
649
|
+
collectionKey = getCollectionKey(key);
|
|
650
|
+
}
|
|
651
|
+
catch (e) {
|
|
652
|
+
// If getCollectionKey() throws an error it means the key is not a collection key.
|
|
653
|
+
collectionKey = undefined;
|
|
654
|
+
}
|
|
655
|
+
if (collectionKey) {
|
|
645
656
|
// Getting the collection key from the specific key because only collection keys were stored in the mapping.
|
|
646
|
-
stateMappingKeys = [...stateMappingKeys, ...((_b = onyxKeyToSubscriptionIDs.get(
|
|
657
|
+
stateMappingKeys = [...stateMappingKeys, ...((_b = onyxKeyToSubscriptionIDs.get(collectionKey)) !== null && _b !== void 0 ? _b : [])];
|
|
647
658
|
if (stateMappingKeys.length === 0) {
|
|
648
659
|
return;
|
|
649
660
|
}
|