react-native-onyx 2.0.118 → 2.0.120

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/README.md CHANGED
@@ -59,6 +59,33 @@ API.Authenticate(params)
59
59
 
60
60
  The data will then be cached and stored via [`AsyncStorage`](https://github.com/react-native-async-storage/async-storage).
61
61
 
62
+ ### Performance Options for Large Objects
63
+
64
+ For performance-critical scenarios with large objects, `Onyx.set()` accepts optional flags to skip expensive operations:
65
+
66
+ ```javascript
67
+ Onyx.set(ONYXKEYS.LARGE_DATA, computedValue, {
68
+ skipCacheCheck: true, // Skip deep equality check
69
+ skipNullRemoval: true, // Skip null value pruning
70
+ });
71
+ ```
72
+
73
+ **Options:**
74
+ - `skipCacheCheck`: Skips the deep equality comparison with the cached value. By default, Onyx compares new values against cached ones to avoid unnecessary updates. For large objects, this comparison can be expensive.
75
+ - `skipNullRemoval`: Skips the removal of `null` values from nested objects. By default, Onyx removes `null` values before storage. Use this when `null` values are meaningful in your data structure.
76
+
77
+ #### When to Use SetOptions
78
+ - **Use `skipCacheCheck: true`** for:
79
+ - Large objects where deep equality checking is expensive
80
+ - Values that you know have changed
81
+
82
+ - **Use `skipNullRemoval: true`** for:
83
+ - Computed values where `null` represents a legitimate result
84
+ - Data structures where `null` has semantic meaning
85
+ - Values that should preserve their exact structure
86
+
87
+ **Note**: These options are recommended only for large objects where performance is critical. Most use cases should use the standard `Onyx.set(key, value)` syntax.
88
+
62
89
  ## Merging data
63
90
 
64
91
  We can also use `Onyx.merge()` to merge new `Object` or `Array` data in with existing data.
package/dist/Onyx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Logger from './Logger';
2
- import type { CollectionKeyBase, ConnectOptions, InitOptions, Mapping, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate } from './types';
2
+ import type { CollectionKeyBase, ConnectOptions, InitOptions, Mapping, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate, SetOptions } from './types';
3
3
  import type { Connection } from './OnyxConnectionManager';
4
4
  /** Initialize the store with actions and listening for storage events */
5
5
  declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, debugSetState, enablePerformanceMetrics, skippableCollectionMemberIDs, fullyMergedSnapshotKeys, }: InitOptions): void;
@@ -49,8 +49,9 @@ declare function disconnect(connection: Connection): void;
49
49
  *
50
50
  * @param key ONYXKEY to set
51
51
  * @param value value to store
52
+ * @param options optional configuration object
52
53
  */
53
- declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>): Promise<void>;
54
+ declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>, options?: SetOptions): Promise<void>;
54
55
  /**
55
56
  * Sets multiple keys and values
56
57
  *
@@ -155,4 +156,4 @@ declare const Onyx: {
155
156
  registerLogger: typeof Logger.registerLogger;
156
157
  };
157
158
  export default Onyx;
158
- export type { OnyxUpdate, Mapping, ConnectOptions };
159
+ export type { OnyxUpdate, Mapping, ConnectOptions, SetOptions };
package/dist/Onyx.js CHANGED
@@ -114,8 +114,9 @@ function disconnect(connection) {
114
114
  *
115
115
  * @param key ONYXKEY to set
116
116
  * @param value value to store
117
+ * @param options optional configuration object
117
118
  */
118
- function set(key, value) {
119
+ function set(key, value, options) {
119
120
  // When we use Onyx.set to set a key we want to clear the current delta changes from Onyx.merge that were queued
120
121
  // before the value was set. If Onyx.merge is currently reading the old value from storage, it will then not apply the changes.
121
122
  if (OnyxUtils_1.default.hasPendingMergeForKey(key)) {
@@ -157,8 +158,8 @@ function set(key, value) {
157
158
  OnyxUtils_1.default.logKeyRemoved(OnyxUtils_1.default.METHOD.SET, key);
158
159
  return Promise.resolve();
159
160
  }
160
- const valueWithoutNestedNullValues = utils_1.default.removeNestedNullValues(value);
161
- const hasChanged = OnyxCache_1.default.hasValueChanged(key, valueWithoutNestedNullValues);
161
+ const valueWithoutNestedNullValues = ((options === null || options === void 0 ? void 0 : options.skipNullRemoval) ? value : utils_1.default.removeNestedNullValues(value));
162
+ const hasChanged = (options === null || options === void 0 ? void 0 : options.skipCacheCheck) ? true : OnyxCache_1.default.hasValueChanged(key, valueWithoutNestedNullValues);
162
163
  OnyxUtils_1.default.logKeyChanged(OnyxUtils_1.default.METHOD.SET, key, value, hasChanged);
163
164
  // This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
164
165
  const updatePromise = OnyxUtils_1.default.broadcastUpdate(key, valueWithoutNestedNullValues, hasChanged);
package/dist/types.d.ts CHANGED
@@ -368,6 +368,15 @@ type OnyxUpdate = {
368
368
  onyxMethod: Method;
369
369
  } & OnyxMethodValueMap[Method];
370
370
  }[OnyxMethod];
371
+ /**
372
+ * Represents the options used in `Onyx.set()` method.
373
+ */
374
+ type SetOptions = {
375
+ /** Skip the deep equality check against the cached value. Improves performance for large objects. */
376
+ skipCacheCheck?: boolean;
377
+ /** Skip pruning null values from the object. Improves performance for large objects. */
378
+ skipNullRemoval?: boolean;
379
+ };
371
380
  /**
372
381
  * Represents the options used in `Onyx.init()` method.
373
382
  */
@@ -428,4 +437,4 @@ type MixedOperationsQueue = {
428
437
  mergeReplaceNullPatches: MultiMergeReplaceNullPatches;
429
438
  set: OnyxInputKeyValueMapping;
430
439
  };
431
- export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, Mapping, NonNull, NonUndefined, OnyxInputKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxMethod, OnyxMethodMap, OnyxUpdate, OnyxValue, Selector, WithOnyxConnectOptions, MultiMergeReplaceNullPatches, MixedOperationsQueue, };
440
+ export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, Mapping, NonNull, NonUndefined, OnyxInputKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxMethod, OnyxMethodMap, OnyxUpdate, OnyxValue, Selector, SetOptions, WithOnyxConnectOptions, MultiMergeReplaceNullPatches, MixedOperationsQueue, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.118",
3
+ "version": "2.0.120",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",