react-native-onyx 2.0.62 → 2.0.64
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 +4 -3
- package/dist/OnyxUtils.d.ts +2 -2
- package/dist/OnyxUtils.js +9 -5
- package/dist/useOnyx.js +3 -1
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -510,8 +510,8 @@ function clear(keysToPreserve = []) {
|
|
|
510
510
|
const newValue = (_a = defaultKeyStates[key]) !== null && _a !== void 0 ? _a : null;
|
|
511
511
|
if (newValue !== oldValue) {
|
|
512
512
|
OnyxCache_1.default.set(key, newValue);
|
|
513
|
-
const collectionKey =
|
|
514
|
-
if (collectionKey) {
|
|
513
|
+
const collectionKey = OnyxUtils_1.default.getCollectionKey(key);
|
|
514
|
+
if (OnyxUtils_1.default.isCollectionKey(collectionKey)) {
|
|
515
515
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
516
516
|
keyValuesToResetAsCollection[collectionKey] = {};
|
|
517
517
|
}
|
|
@@ -560,6 +560,7 @@ function updateSnapshots(data) {
|
|
|
560
560
|
return;
|
|
561
561
|
const promises = [];
|
|
562
562
|
const snapshotCollection = OnyxUtils_1.default.getCachedCollection(snapshotCollectionKey);
|
|
563
|
+
const snapshotCollectionKeyLength = snapshotCollectionKey.length;
|
|
563
564
|
Object.entries(snapshotCollection).forEach(([snapshotKey, snapshotValue]) => {
|
|
564
565
|
// Snapshots may not be present in cache. We don't know how to update them so we skip.
|
|
565
566
|
if (!snapshotValue) {
|
|
@@ -568,7 +569,7 @@ function updateSnapshots(data) {
|
|
|
568
569
|
let updatedData = {};
|
|
569
570
|
data.forEach(({ key, value }) => {
|
|
570
571
|
// snapshots are normal keys so we want to skip update if they are written to Onyx
|
|
571
|
-
if (OnyxUtils_1.default.isCollectionMemberKey(snapshotCollectionKey, key)) {
|
|
572
|
+
if (OnyxUtils_1.default.isCollectionMemberKey(snapshotCollectionKey, key, snapshotCollectionKeyLength)) {
|
|
572
573
|
return;
|
|
573
574
|
}
|
|
574
575
|
if (typeof snapshotValue !== 'object' || !('data' in snapshotValue)) {
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -79,13 +79,13 @@ declare function getCollectionKeys(): Set<OnyxKey>;
|
|
|
79
79
|
* is associated with a collection of keys.
|
|
80
80
|
*/
|
|
81
81
|
declare function isCollectionKey(key: OnyxKey): key is CollectionKeyBase;
|
|
82
|
-
declare function isCollectionMemberKey<TCollectionKey extends CollectionKeyBase>(collectionKey: TCollectionKey, key: string): key is `${TCollectionKey}${string}`;
|
|
82
|
+
declare function isCollectionMemberKey<TCollectionKey extends CollectionKeyBase>(collectionKey: TCollectionKey, key: string, collectionKeyLength: number): key is `${TCollectionKey}${string}`;
|
|
83
83
|
/**
|
|
84
84
|
* Splits a collection member key into the collection key part and the ID part.
|
|
85
85
|
* @param key - The collection member key to split.
|
|
86
86
|
* @returns A tuple where the first element is the collection part and the second element is the ID part.
|
|
87
87
|
*/
|
|
88
|
-
declare function splitCollectionMemberKey<TKey extends CollectionKey
|
|
88
|
+
declare function splitCollectionMemberKey<TKey extends CollectionKey, CollectionKeyType = TKey extends `${infer Prefix}_${string}` ? `${Prefix}_` : never>(key: TKey): [CollectionKeyType, string];
|
|
89
89
|
/**
|
|
90
90
|
* Checks to see if a provided key is the exact configured key of our connected subscriber
|
|
91
91
|
* or if the provided key is a collection member key (in case our configured key is a "collection key")
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -315,8 +315,8 @@ function getCollectionKeys() {
|
|
|
315
315
|
function isCollectionKey(key) {
|
|
316
316
|
return onyxCollectionKeySet.has(key);
|
|
317
317
|
}
|
|
318
|
-
function isCollectionMemberKey(collectionKey, key) {
|
|
319
|
-
return
|
|
318
|
+
function isCollectionMemberKey(collectionKey, key, collectionKeyLength) {
|
|
319
|
+
return key.startsWith(collectionKey) && key.length > collectionKeyLength;
|
|
320
320
|
}
|
|
321
321
|
/**
|
|
322
322
|
* Splits a collection member key into the collection key part and the ID part.
|
|
@@ -328,7 +328,9 @@ function splitCollectionMemberKey(key) {
|
|
|
328
328
|
if (underscoreIndex === -1) {
|
|
329
329
|
throw new Error(`Invalid ${key} key provided, only collection keys are allowed.`);
|
|
330
330
|
}
|
|
331
|
-
|
|
331
|
+
const collectionKey = key.substring(0, underscoreIndex + 1);
|
|
332
|
+
const memberKey = key.substring(underscoreIndex + 1);
|
|
333
|
+
return [collectionKey, memberKey];
|
|
332
334
|
}
|
|
333
335
|
/**
|
|
334
336
|
* Checks to see if a provided key is the exact configured key of our connected subscriber
|
|
@@ -450,12 +452,13 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
450
452
|
function getCachedCollection(collectionKey, collectionMemberKeys) {
|
|
451
453
|
const allKeys = collectionMemberKeys || OnyxCache_1.default.getAllKeys();
|
|
452
454
|
const collection = {};
|
|
455
|
+
const collectionKeyLength = collectionKey.length;
|
|
453
456
|
// forEach exists on both Set and Array
|
|
454
457
|
allKeys.forEach((key) => {
|
|
455
458
|
// If we don't have collectionMemberKeys array then we have to check whether a key is a collection member key.
|
|
456
459
|
// Because in that case the keys will be coming from `cache.getAllKeys()` and we need to filter out the keys that
|
|
457
460
|
// are not part of the collection.
|
|
458
|
-
if (!collectionMemberKeys && !isCollectionMemberKey(collectionKey, key)) {
|
|
461
|
+
if (!collectionMemberKeys && !isCollectionMemberKey(collectionKey, key, collectionKeyLength)) {
|
|
459
462
|
return;
|
|
460
463
|
}
|
|
461
464
|
const cachedValue = OnyxCache_1.default.get(key);
|
|
@@ -478,6 +481,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
478
481
|
// individual collection key member for the collection that is being updated. It is important to note that the collection parameter cane be a PARTIAL collection
|
|
479
482
|
// and does not represent all of the combined keys and values for a collection key. It is just the "new" data that was merged in via mergeCollection().
|
|
480
483
|
const stateMappingKeys = Object.keys(callbackToStateMapping);
|
|
484
|
+
const collectionKeyLength = collectionKey.length;
|
|
481
485
|
for (let i = 0; i < stateMappingKeys.length; i++) {
|
|
482
486
|
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
|
|
483
487
|
if (!subscriber) {
|
|
@@ -494,7 +498,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
494
498
|
/**
|
|
495
499
|
* e.g. Onyx.connect({key: `${ONYXKEYS.COLLECTION.REPORT}{reportID}`, callback: ...});
|
|
496
500
|
*/
|
|
497
|
-
const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key);
|
|
501
|
+
const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key, collectionKeyLength);
|
|
498
502
|
// Regular Onyx.connect() subscriber found.
|
|
499
503
|
if (typeof subscriber.callback === 'function') {
|
|
500
504
|
if (!notifyRegularSubscibers) {
|
package/dist/useOnyx.js
CHANGED
|
@@ -46,7 +46,9 @@ function useOnyx(key, options) {
|
|
|
46
46
|
try {
|
|
47
47
|
const previousCollectionKey = OnyxUtils_1.default.splitCollectionMemberKey(previousKey)[0];
|
|
48
48
|
const collectionKey = OnyxUtils_1.default.splitCollectionMemberKey(key)[0];
|
|
49
|
-
if (OnyxUtils_1.default.isCollectionMemberKey(previousCollectionKey, previousKey
|
|
49
|
+
if (OnyxUtils_1.default.isCollectionMemberKey(previousCollectionKey, previousKey, previousCollectionKey.length) &&
|
|
50
|
+
OnyxUtils_1.default.isCollectionMemberKey(collectionKey, key, collectionKey.length) &&
|
|
51
|
+
previousCollectionKey === collectionKey) {
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
54
|
}
|