react-native-onyx 3.0.5 → 3.0.7

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 CHANGED
@@ -343,7 +343,7 @@ function merge(key, changes) {
343
343
  * @param collection Object collection keyed by individual collection member keys and values
344
344
  */
345
345
  function mergeCollection(collectionKey, collection) {
346
- return OnyxUtils_1.default.mergeCollectionWithPatches(collectionKey, collection);
346
+ return OnyxUtils_1.default.mergeCollectionWithPatches(collectionKey, collection, undefined, true);
347
347
  }
348
348
  /**
349
349
  * Clear out all the data in the store
@@ -552,7 +552,7 @@ function update(data) {
552
552
  set: {},
553
553
  });
554
554
  if (!utils_1.default.isEmptyObject(batchedCollectionUpdates.merge)) {
555
- promises.push(() => OnyxUtils_1.default.mergeCollectionWithPatches(collectionKey, batchedCollectionUpdates.merge, batchedCollectionUpdates.mergeReplaceNullPatches));
555
+ promises.push(() => OnyxUtils_1.default.mergeCollectionWithPatches(collectionKey, batchedCollectionUpdates.merge, batchedCollectionUpdates.mergeReplaceNullPatches, true));
556
556
  }
557
557
  if (!utils_1.default.isEmptyObject(batchedCollectionUpdates.set)) {
558
558
  promises.push(() => OnyxUtils_1.default.partialSetCollection(collectionKey, batchedCollectionUpdates.set));
@@ -623,7 +623,7 @@ function setCollection(collectionKey, collection) {
623
623
  }
624
624
  mutableCollection[key] = null;
625
625
  });
626
- const keyValuePairs = OnyxUtils_1.default.prepareKeyValuePairsForStorage(mutableCollection, true);
626
+ const keyValuePairs = OnyxUtils_1.default.prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
627
627
  const previousCollection = OnyxUtils_1.default.getCachedCollection(collectionKey);
628
628
  keyValuePairs.forEach(([key, value]) => OnyxCache_1.default.set(key, value));
629
629
  const updatePromise = OnyxUtils_1.default.scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
@@ -149,7 +149,7 @@ declare function keysChanged<TKey extends CollectionKeyBase>(collectionKey: TKey
149
149
  * @example
150
150
  * keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
151
151
  */
152
- declare function keyChanged<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: CallbackToStateMapping<OnyxKey>) => boolean, notifyConnectSubscribers?: boolean): void;
152
+ declare function keyChanged<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: CallbackToStateMapping<OnyxKey>) => boolean, notifyConnectSubscribers?: boolean, isProcessingCollectionUpdate?: boolean): void;
153
153
  /**
154
154
  * Sends the data obtained from the keys to the connection.
155
155
  */
@@ -169,7 +169,7 @@ declare function getCollectionDataAndSendAsObject<TKey extends OnyxKey>(matching
169
169
  * @example
170
170
  * scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
171
171
  */
172
- declare function scheduleSubscriberUpdate<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: CallbackToStateMapping<OnyxKey>) => boolean): Promise<void>;
172
+ declare function scheduleSubscriberUpdate<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: CallbackToStateMapping<OnyxKey>) => boolean, isProcessingCollectionUpdate?: boolean): Promise<void>;
173
173
  /**
174
174
  * This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections
175
175
  * so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
@@ -179,7 +179,7 @@ declare function scheduleNotifyCollectionSubscribers<TKey extends OnyxKey>(key:
179
179
  /**
180
180
  * Remove a key from Onyx and update the subscribers
181
181
  */
182
- declare function remove<TKey extends OnyxKey>(key: TKey): Promise<void>;
182
+ declare function remove<TKey extends OnyxKey>(key: TKey, isProcessingCollectionUpdate?: boolean): Promise<void>;
183
183
  declare function reportStorageQuota(): Promise<void>;
184
184
  /**
185
185
  * If we fail to set or merge we must handle this by
@@ -199,7 +199,7 @@ declare function hasPendingMergeForKey(key: OnyxKey): boolean;
199
199
  *
200
200
  * @return an array of key - value pairs <[key, value]>
201
201
  */
202
- declare function prepareKeyValuePairsForStorage(data: Record<OnyxKey, OnyxInput<OnyxKey>>, shouldRemoveNestedNulls?: boolean, replaceNullPatches?: MultiMergeReplaceNullPatches): StorageKeyValuePair[];
202
+ declare function prepareKeyValuePairsForStorage(data: Record<OnyxKey, OnyxInput<OnyxKey>>, shouldRemoveNestedNulls?: boolean, replaceNullPatches?: MultiMergeReplaceNullPatches, isProcessingCollectionUpdate?: boolean): StorageKeyValuePair[];
203
203
  /**
204
204
  * Merges an array of changes with an existing value or creates a single change.
205
205
  *
@@ -251,7 +251,7 @@ declare function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge)
251
251
  * @param mergeReplaceNullPatches Record where the key is a collection member key and the value is a list of
252
252
  * tuples that we'll use to replace the nested objects of that collection member record with something else.
253
253
  */
254
- declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>, mergeReplaceNullPatches?: MultiMergeReplaceNullPatches): Promise<void>;
254
+ declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>, mergeReplaceNullPatches?: MultiMergeReplaceNullPatches, isProcessingCollectionUpdate?: boolean): Promise<void>;
255
255
  /**
256
256
  * Sets keys in a collection by replacing all targeted collection members with new values.
257
257
  * Any existing collection members not included in the new data will not be removed.
package/dist/OnyxUtils.js CHANGED
@@ -564,7 +564,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
564
564
  * @example
565
565
  * keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
566
566
  */
567
- function keyChanged(key, value, canUpdateSubscriber = () => true, notifyConnectSubscribers = true) {
567
+ function keyChanged(key, value, canUpdateSubscriber = () => true, notifyConnectSubscribers = true, isProcessingCollectionUpdate = false) {
568
568
  var _a, _b;
569
569
  // Add or remove this key from the recentlyAccessedKeys lists
570
570
  if (value !== null) {
@@ -609,6 +609,11 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, notifyConnectS
609
609
  continue;
610
610
  }
611
611
  if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) {
612
+ // Skip individual key changes for collection callbacks during collection updates
613
+ // to prevent duplicate callbacks - the collection update will handle this properly
614
+ if (isProcessingCollectionUpdate) {
615
+ continue;
616
+ }
612
617
  let cachedCollection = cachedCollections[subscriber.key];
613
618
  if (!cachedCollection) {
614
619
  cachedCollection = getCachedCollection(subscriber.key);
@@ -674,9 +679,9 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
674
679
  * @example
675
680
  * scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
676
681
  */
677
- function scheduleSubscriberUpdate(key, value, canUpdateSubscriber = () => true) {
678
- const promise = Promise.resolve().then(() => keyChanged(key, value, canUpdateSubscriber, true));
679
- batchUpdates(() => keyChanged(key, value, canUpdateSubscriber, false));
682
+ function scheduleSubscriberUpdate(key, value, canUpdateSubscriber = () => true, isProcessingCollectionUpdate = false) {
683
+ const promise = Promise.resolve().then(() => keyChanged(key, value, canUpdateSubscriber, true, isProcessingCollectionUpdate));
684
+ batchUpdates(() => keyChanged(key, value, canUpdateSubscriber, false, isProcessingCollectionUpdate));
680
685
  return Promise.all([maybeFlushBatchUpdates(), promise]).then(() => undefined);
681
686
  }
682
687
  /**
@@ -692,9 +697,9 @@ function scheduleNotifyCollectionSubscribers(key, value, previousValue) {
692
697
  /**
693
698
  * Remove a key from Onyx and update the subscribers
694
699
  */
695
- function remove(key) {
700
+ function remove(key, isProcessingCollectionUpdate) {
696
701
  OnyxCache_1.default.drop(key);
697
- scheduleSubscriberUpdate(key, undefined);
702
+ scheduleSubscriberUpdate(key, undefined, undefined, isProcessingCollectionUpdate);
698
703
  return storage_1.default.removeItem(key).then(() => undefined);
699
704
  }
700
705
  function reportStorageQuota() {
@@ -756,11 +761,11 @@ function hasPendingMergeForKey(key) {
756
761
  *
757
762
  * @return an array of key - value pairs <[key, value]>
758
763
  */
759
- function prepareKeyValuePairsForStorage(data, shouldRemoveNestedNulls, replaceNullPatches) {
764
+ function prepareKeyValuePairsForStorage(data, shouldRemoveNestedNulls, replaceNullPatches, isProcessingCollectionUpdate) {
760
765
  const pairs = [];
761
766
  Object.entries(data).forEach(([key, value]) => {
762
767
  if (value === null) {
763
- remove(key);
768
+ remove(key, isProcessingCollectionUpdate);
764
769
  return;
765
770
  }
766
771
  const valueWithoutNestedNullValues = (shouldRemoveNestedNulls !== null && shouldRemoveNestedNulls !== void 0 ? shouldRemoveNestedNulls : true) ? utils_1.default.removeNestedNullValues(value) : value;
@@ -1010,7 +1015,7 @@ function updateSnapshots(data, mergeFn) {
1010
1015
  * @param mergeReplaceNullPatches Record where the key is a collection member key and the value is a list of
1011
1016
  * tuples that we'll use to replace the nested objects of that collection member record with something else.
1012
1017
  */
1013
- function mergeCollectionWithPatches(collectionKey, collection, mergeReplaceNullPatches) {
1018
+ function mergeCollectionWithPatches(collectionKey, collection, mergeReplaceNullPatches, isProcessingCollectionUpdate = false) {
1014
1019
  if (!isValidNonEmptyCollectionForMerge(collection)) {
1015
1020
  Logger.logInfo('mergeCollection() called with invalid or empty value. Skipping this update.');
1016
1021
  return Promise.resolve();
@@ -1043,7 +1048,7 @@ function mergeCollectionWithPatches(collectionKey, collection, mergeReplaceNullP
1043
1048
  // Split to keys that exist in storage and keys that don't
1044
1049
  const keys = resultCollectionKeys.filter((key) => {
1045
1050
  if (resultCollection[key] === null) {
1046
- remove(key);
1051
+ remove(key, isProcessingCollectionUpdate);
1047
1052
  return false;
1048
1053
  }
1049
1054
  return true;
@@ -1139,7 +1144,7 @@ function partialSetCollection(collectionKey, collection) {
1139
1144
  const mutableCollection = Object.assign({}, resultCollection);
1140
1145
  const existingKeys = resultCollectionKeys.filter((key) => persistedKeys.has(key));
1141
1146
  const previousCollection = getCachedCollection(collectionKey, existingKeys);
1142
- const keyValuePairs = prepareKeyValuePairsForStorage(mutableCollection, true);
1147
+ const keyValuePairs = prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
1143
1148
  keyValuePairs.forEach(([key, value]) => OnyxCache_1.default.set(key, value));
1144
1149
  const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
1145
1150
  return storage_1.default.multiSet(keyValuePairs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",