Skip to content

Commit 83d6a10

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/skippable-collection-member-ids
2 parents d65b1ec + 9bbb724 commit 83d6a10

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/Onyx.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,19 @@ function setCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey
848848
mutableCollection[key] = null;
849849
});
850850

851-
return multiSet(mutableCollection);
851+
const keyValuePairs = OnyxUtils.prepareKeyValuePairsForStorage(mutableCollection, true);
852+
const previousCollection = OnyxUtils.getCachedCollection(collectionKey);
853+
854+
keyValuePairs.forEach(([key, value]) => cache.set(key, value));
855+
856+
const updatePromise = OnyxUtils.scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
857+
858+
return Storage.multiSet(keyValuePairs)
859+
.catch((error) => OnyxUtils.evictStorageAndRetry(error, setCollection, collectionKey, collection))
860+
.then(() => {
861+
OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.SET_COLLECTION, undefined, mutableCollection);
862+
return updatePromise;
863+
});
852864
});
853865
}
854866

lib/OnyxUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ function initStoreValues(keys: DeepRecord<string, OnyxKey>, initialKeyStates: Pa
181181
* @param mergedValue - (optional) value that was written in the storage after a merge method was executed.
182182
*/
183183
function sendActionToDevTools(
184-
method: typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET,
184+
method: typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET | typeof METHOD.SET_COLLECTION,
185185
key: undefined,
186186
value: OnyxCollection<KeyValueMapping[OnyxKey]>,
187187
mergedValue?: undefined,
188188
): void;
189189
function sendActionToDevTools(
190-
method: Exclude<OnyxMethod, typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET>,
190+
method: Exclude<OnyxMethod, typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET | typeof METHOD.SET_COLLECTION>,
191191
key: OnyxKey,
192192
value: OnyxEntry<KeyValueMapping[OnyxKey]>,
193193
mergedValue?: OnyxEntry<KeyValueMapping[OnyxKey]>,
@@ -1139,7 +1139,7 @@ function reportStorageQuota(): Promise<void> {
11391139
* evicting some data from Onyx and then retrying to do
11401140
* whatever it is we attempted to do.
11411141
*/
1142-
function evictStorageAndRetry<TMethod extends typeof Onyx.set | typeof Onyx.multiSet | typeof Onyx.mergeCollection>(
1142+
function evictStorageAndRetry<TMethod extends typeof Onyx.set | typeof Onyx.multiSet | typeof Onyx.mergeCollection | typeof Onyx.setCollection>(
11431143
error: Error,
11441144
onyxMethod: TMethod,
11451145
...args: Parameters<TMethod>

0 commit comments

Comments
 (0)