react-native-onyx 3.0.12 → 3.0.14

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.
@@ -1,6 +1,6 @@
1
1
  import type { ValueOf } from 'type-fest';
2
2
  import type Onyx from './Onyx';
3
- import type { CollectionKey, CollectionKeyBase, ConnectOptions, DeepRecord, KeyValueMapping, CallbackToStateMapping, MultiMergeReplaceNullPatches, OnyxCollection, OnyxEntry, OnyxInput, OnyxInputKeyValueMapping, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, MergeCollectionWithPatchesParams, SetCollectionParams, SetParams, OnyxMultiSetInput, RetriableOnyxOperation } from './types';
3
+ import type { CollectionKey, CollectionKeyBase, ConnectOptions, DeepRecord, KeyValueMapping, CallbackToStateMapping, MultiMergeReplaceNullPatches, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, MergeCollectionWithPatchesParams, SetCollectionParams, SetParams, OnyxMultiSetInput, RetriableOnyxOperation } from './types';
4
4
  import type { FastMergeResult } from './utils';
5
5
  import type { DeferredTask } from './createDeferredTask';
6
6
  import type { StorageKeyValuePair } from './storage/providers/types';
@@ -138,18 +138,6 @@ declare function getCollectionKey(key: CollectionKey): string;
138
138
  * If the requested key is a collection, it will return an object with all the collection members.
139
139
  */
140
140
  declare function tryGetCachedValue<TKey extends OnyxKey>(key: TKey): OnyxValue<OnyxKey>;
141
- /**
142
- * Utility function to preserve object references for unchanged items in collection operations.
143
- * Compares new values with cached values using deep equality and preserves references when data is identical.
144
- * @returns The preserved collection with unchanged references maintained
145
- */
146
- declare function preserveCollectionReferences(keyValuePairs: StorageKeyValuePair[]): OnyxInputKeyValueMapping;
147
- /**
148
- * Utility function for merge operations that preserves references after cache merge has been performed.
149
- * Compares merged values with original cached values and preserves references when data is unchanged.
150
- * @returns The preserved collection with unchanged references maintained
151
- */
152
- declare function preserveCollectionReferencesAfterMerge(collection: Record<string, OnyxValue<OnyxKey>>, originalCachedValues: Record<string, OnyxValue<OnyxKey>>): Record<string, OnyxValue<OnyxKey>>;
153
141
  declare function getCachedCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collectionMemberKeys?: string[]): NonNullable<OnyxCollection<KeyValueMapping[TKey]>>;
154
142
  /**
155
143
  * When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks
@@ -376,8 +364,6 @@ declare const OnyxUtils: {
376
364
  updateSnapshots: typeof updateSnapshots;
377
365
  mergeCollectionWithPatches: typeof mergeCollectionWithPatches;
378
366
  partialSetCollection: typeof partialSetCollection;
379
- preserveCollectionReferences: typeof preserveCollectionReferences;
380
- preserveCollectionReferencesAfterMerge: typeof preserveCollectionReferencesAfterMerge;
381
367
  logKeyChanged: typeof logKeyChanged;
382
368
  logKeyRemoved: typeof logKeyRemoved;
383
369
  setWithRetry: typeof setWithRetry;
package/dist/OnyxUtils.js CHANGED
@@ -465,51 +465,6 @@ function tryGetCachedValue(key) {
465
465
  }
466
466
  return val;
467
467
  }
468
- /**
469
- * Utility function to preserve object references for unchanged items in collection operations.
470
- * Compares new values with cached values using deep equality and preserves references when data is identical.
471
- * @returns The preserved collection with unchanged references maintained
472
- */
473
- function preserveCollectionReferences(keyValuePairs) {
474
- const preservedCollection = {};
475
- keyValuePairs.forEach(([key, value]) => {
476
- const cachedValue = OnyxCache_1.default.get(key, false);
477
- // If no cached value exists, we need to add the new value (skip expensive deep equality check)
478
- // Use deep equality check to preserve references for unchanged items
479
- if (cachedValue !== undefined && (0, fast_equals_1.deepEqual)(value, cachedValue)) {
480
- // Keep the existing reference
481
- preservedCollection[key] = cachedValue;
482
- }
483
- else {
484
- // Update cache only for changed items
485
- OnyxCache_1.default.set(key, value);
486
- preservedCollection[key] = value;
487
- }
488
- });
489
- return preservedCollection;
490
- }
491
- /**
492
- * Utility function for merge operations that preserves references after cache merge has been performed.
493
- * Compares merged values with original cached values and preserves references when data is unchanged.
494
- * @returns The preserved collection with unchanged references maintained
495
- */
496
- function preserveCollectionReferencesAfterMerge(collection, originalCachedValues) {
497
- const preservedCollection = {};
498
- Object.keys(collection).forEach((key) => {
499
- const newMergedValue = OnyxCache_1.default.get(key, false);
500
- const originalValue = originalCachedValues[key];
501
- // Use deep equality check to preserve references for unchanged items
502
- if (originalValue !== undefined && (0, fast_equals_1.deepEqual)(newMergedValue, originalValue)) {
503
- // Keep the existing reference and update cache
504
- preservedCollection[key] = originalValue;
505
- OnyxCache_1.default.set(key, originalValue);
506
- }
507
- else {
508
- preservedCollection[key] = newMergedValue;
509
- }
510
- });
511
- return preservedCollection;
512
- }
513
468
  function getCachedCollection(collectionKey, collectionMemberKeys) {
514
469
  // Use optimized collection data retrieval when cache is populated
515
470
  const collectionData = OnyxCache_1.default.getCollectionData(collectionKey);
@@ -1240,9 +1195,8 @@ function setCollectionWithRetry({ collectionKey, collection }, retryAttempt) {
1240
1195
  });
1241
1196
  const keyValuePairs = OnyxUtils.prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
1242
1197
  const previousCollection = OnyxUtils.getCachedCollection(collectionKey);
1243
- // Preserve references for unchanged items in setCollection
1244
- const preservedCollection = OnyxUtils.preserveCollectionReferences(keyValuePairs);
1245
- const updatePromise = OnyxUtils.scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
1198
+ keyValuePairs.forEach(([key, value]) => OnyxCache_1.default.set(key, value));
1199
+ const updatePromise = OnyxUtils.scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
1246
1200
  return storage_1.default.multiSet(keyValuePairs)
1247
1201
  .catch((error) => OnyxUtils.retryOperation(error, setCollectionWithRetry, { collectionKey, collection }, retryAttempt))
1248
1202
  .then(() => {
@@ -1343,18 +1297,10 @@ function mergeCollectionWithPatches({ collectionKey, collection, mergeReplaceNul
1343
1297
  // finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
1344
1298
  const finalMergedCollection = Object.assign(Object.assign({}, existingKeyCollection), newCollection);
1345
1299
  // Prefill cache if necessary by calling get() on any existing keys and then merge original data to cache
1346
- // and update all subscribers with reference preservation for unchanged items
1300
+ // and update all subscribers
1347
1301
  const promiseUpdate = previousCollectionPromise.then((previousCollection) => {
1348
- // Capture the original cached values before merging
1349
- const originalCachedValues = {};
1350
- Object.keys(finalMergedCollection).forEach((key) => {
1351
- originalCachedValues[key] = OnyxCache_1.default.get(key, false);
1352
- });
1353
- // Then merge all the data into cache as normal
1354
1302
  OnyxCache_1.default.merge(finalMergedCollection);
1355
- // Finally, preserve references for items that didn't actually change
1356
- const preservedCollection = preserveCollectionReferencesAfterMerge(finalMergedCollection, originalCachedValues);
1357
- return scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
1303
+ return scheduleNotifyCollectionSubscribers(collectionKey, finalMergedCollection, previousCollection);
1358
1304
  });
1359
1305
  return Promise.all(promises)
1360
1306
  .catch((error) => retryOperation(error, mergeCollectionWithPatches, { collectionKey, collection: resultCollection, mergeReplaceNullPatches, isProcessingCollectionUpdate }, retryAttempt))
@@ -1405,9 +1351,8 @@ function partialSetCollection({ collectionKey, collection }, retryAttempt) {
1405
1351
  const existingKeys = resultCollectionKeys.filter((key) => persistedKeys.has(key));
1406
1352
  const previousCollection = getCachedCollection(collectionKey, existingKeys);
1407
1353
  const keyValuePairs = prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
1408
- // Preserve references for unchanged items in partialSetCollection
1409
- const preservedCollection = preserveCollectionReferences(keyValuePairs);
1410
- const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
1354
+ keyValuePairs.forEach(([key, value]) => OnyxCache_1.default.set(key, value));
1355
+ const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
1411
1356
  return storage_1.default.multiSet(keyValuePairs)
1412
1357
  .catch((error) => retryOperation(error, partialSetCollection, { collectionKey, collection }, retryAttempt))
1413
1358
  .then(() => {
@@ -1484,8 +1429,6 @@ const OnyxUtils = {
1484
1429
  updateSnapshots,
1485
1430
  mergeCollectionWithPatches,
1486
1431
  partialSetCollection,
1487
- preserveCollectionReferences,
1488
- preserveCollectionReferencesAfterMerge,
1489
1432
  logKeyChanged,
1490
1433
  logKeyRemoved,
1491
1434
  setWithRetry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.12",
3
+ "version": "3.0.14",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -90,8 +90,8 @@
90
90
  "react-dom": "18.2.0",
91
91
  "react-native": "0.76.3",
92
92
  "react-native-device-info": "^10.3.0",
93
- "react-native-nitro-modules": "^0.26.2",
94
- "react-native-nitro-sqlite": "^9.1.10",
93
+ "react-native-nitro-modules": "^0.27.2",
94
+ "react-native-nitro-sqlite": "^9.2.0",
95
95
  "react-native-performance": "^2.0.0",
96
96
  "react-test-renderer": "18.2.0",
97
97
  "reassure": "1.4.0",
@@ -105,8 +105,8 @@
105
105
  "react-dom": ">=18.1.0",
106
106
  "react-native": ">=0.75.0",
107
107
  "react-native-device-info": "^10.3.0",
108
- "react-native-nitro-modules": ">=0.26.2",
109
- "react-native-nitro-sqlite": "^9.1.10",
108
+ "react-native-nitro-modules": ">=0.27.2",
109
+ "react-native-nitro-sqlite": "^9.2.0",
110
110
  "react-native-performance": "^5.1.0"
111
111
  },
112
112
  "peerDependenciesMeta": {