react-native-onyx 2.0.61 → 2.0.63
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 +2 -1
- package/dist/OnyxUtils.d.ts +1 -1
- package/dist/OnyxUtils.js +12 -5
- package/dist/useOnyx.js +3 -1
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -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,7 +79,7 @@ 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.
|
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.
|
|
@@ -450,12 +450,13 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
450
450
|
function getCachedCollection(collectionKey, collectionMemberKeys) {
|
|
451
451
|
const allKeys = collectionMemberKeys || OnyxCache_1.default.getAllKeys();
|
|
452
452
|
const collection = {};
|
|
453
|
+
const collectionKeyLength = collectionKey.length;
|
|
453
454
|
// forEach exists on both Set and Array
|
|
454
455
|
allKeys.forEach((key) => {
|
|
455
456
|
// If we don't have collectionMemberKeys array then we have to check whether a key is a collection member key.
|
|
456
457
|
// Because in that case the keys will be coming from `cache.getAllKeys()` and we need to filter out the keys that
|
|
457
458
|
// are not part of the collection.
|
|
458
|
-
if (!collectionMemberKeys && !isCollectionMemberKey(collectionKey, key)) {
|
|
459
|
+
if (!collectionMemberKeys && !isCollectionMemberKey(collectionKey, key, collectionKeyLength)) {
|
|
459
460
|
return;
|
|
460
461
|
}
|
|
461
462
|
const cachedValue = OnyxCache_1.default.get(key);
|
|
@@ -478,6 +479,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
478
479
|
// 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
480
|
// 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
481
|
const stateMappingKeys = Object.keys(callbackToStateMapping);
|
|
482
|
+
const collectionKeyLength = collectionKey.length;
|
|
481
483
|
for (let i = 0; i < stateMappingKeys.length; i++) {
|
|
482
484
|
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
|
|
483
485
|
if (!subscriber) {
|
|
@@ -494,7 +496,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
494
496
|
/**
|
|
495
497
|
* e.g. Onyx.connect({key: `${ONYXKEYS.COLLECTION.REPORT}{reportID}`, callback: ...});
|
|
496
498
|
*/
|
|
497
|
-
const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key);
|
|
499
|
+
const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key, collectionKeyLength);
|
|
498
500
|
// Regular Onyx.connect() subscriber found.
|
|
499
501
|
if (typeof subscriber.callback === 'function') {
|
|
500
502
|
if (!notifyRegularSubscibers) {
|
|
@@ -653,6 +655,7 @@ function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true,
|
|
|
653
655
|
return;
|
|
654
656
|
}
|
|
655
657
|
}
|
|
658
|
+
const cachedCollections = {};
|
|
656
659
|
for (let i = 0; i < stateMappingKeys.length; i++) {
|
|
657
660
|
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
|
|
658
661
|
if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
|
|
@@ -667,7 +670,11 @@ function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true,
|
|
|
667
670
|
continue;
|
|
668
671
|
}
|
|
669
672
|
if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) {
|
|
670
|
-
|
|
673
|
+
let cachedCollection = cachedCollections[subscriber.key];
|
|
674
|
+
if (!cachedCollection) {
|
|
675
|
+
cachedCollection = getCachedCollection(subscriber.key);
|
|
676
|
+
cachedCollections[subscriber.key] = cachedCollection;
|
|
677
|
+
}
|
|
671
678
|
cachedCollection[key] = value;
|
|
672
679
|
subscriber.callback(cachedCollection);
|
|
673
680
|
continue;
|
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
|
}
|