react-native-onyx 3.0.9 → 3.0.11
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.d.ts +3 -3
- package/dist/Onyx.js +3 -2
- package/dist/OnyxUtils.d.ts +18 -4
- package/dist/OnyxUtils.js +60 -4
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +38 -35
- package/package.json +2 -1
package/dist/Onyx.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Logger from './Logger';
|
|
2
|
-
import type { CollectionKeyBase, ConnectOptions, InitOptions, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate, SetOptions } from './types';
|
|
2
|
+
import type { CollectionKeyBase, ConnectOptions, InitOptions, OnyxKey, OnyxMergeCollectionInput, OnyxSetCollectionInput, 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, enablePerformanceMetrics, enableDevTools, skippableCollectionMemberIDs, }: InitOptions): void;
|
|
@@ -110,7 +110,7 @@ declare function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<
|
|
|
110
110
|
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
111
111
|
* @param collection Object collection keyed by individual collection member keys and values
|
|
112
112
|
*/
|
|
113
|
-
declare function mergeCollection<TKey extends CollectionKeyBase
|
|
113
|
+
declare function mergeCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey>): Promise<void>;
|
|
114
114
|
/**
|
|
115
115
|
* Clear out all the data in the store
|
|
116
116
|
*
|
|
@@ -153,7 +153,7 @@ declare function update(data: OnyxUpdate[]): Promise<void>;
|
|
|
153
153
|
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
154
154
|
* @param collection Object collection keyed by individual collection member keys and values
|
|
155
155
|
*/
|
|
156
|
-
declare function setCollection<TKey extends CollectionKeyBase
|
|
156
|
+
declare function setCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collection: OnyxSetCollectionInput<TKey>): Promise<void>;
|
|
157
157
|
declare const Onyx: {
|
|
158
158
|
METHOD: {
|
|
159
159
|
readonly SET: "set";
|
package/dist/Onyx.js
CHANGED
|
@@ -626,8 +626,9 @@ function setCollection(collectionKey, collection) {
|
|
|
626
626
|
});
|
|
627
627
|
const keyValuePairs = OnyxUtils_1.default.prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
|
|
628
628
|
const previousCollection = OnyxUtils_1.default.getCachedCollection(collectionKey);
|
|
629
|
-
|
|
630
|
-
const
|
|
629
|
+
// Preserve references for unchanged items in setCollection
|
|
630
|
+
const preservedCollection = OnyxUtils_1.default.preserveCollectionReferences(keyValuePairs);
|
|
631
|
+
const updatePromise = OnyxUtils_1.default.scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
|
|
631
632
|
return storage_1.default.multiSet(keyValuePairs)
|
|
632
633
|
.catch((error) => OnyxUtils_1.default.evictStorageAndRetry(error, setCollection, collectionKey, collection))
|
|
633
634
|
.then(() => {
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -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, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector } from './types';
|
|
3
|
+
import type { CollectionKey, CollectionKeyBase, ConnectOptions, DeepRecord, KeyValueMapping, CallbackToStateMapping, MultiMergeReplaceNullPatches, OnyxCollection, OnyxEntry, OnyxInput, OnyxInputKeyValueMapping, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, OnyxSetCollectionInput } 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,6 +138,18 @@ 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>>;
|
|
141
153
|
declare function getCachedCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collectionMemberKeys?: string[]): NonNullable<OnyxCollection<KeyValueMapping[TKey]>>;
|
|
142
154
|
/**
|
|
143
155
|
* When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks
|
|
@@ -222,7 +234,7 @@ declare function initializeWithDefaultKeyStates(): Promise<void>;
|
|
|
222
234
|
/**
|
|
223
235
|
* Validate the collection is not empty and has a correct type before applying mergeCollection()
|
|
224
236
|
*/
|
|
225
|
-
declare function isValidNonEmptyCollectionForMerge<TKey extends CollectionKeyBase
|
|
237
|
+
declare function isValidNonEmptyCollectionForMerge<TKey extends CollectionKeyBase>(collection: OnyxMergeCollectionInput<TKey>): boolean;
|
|
226
238
|
/**
|
|
227
239
|
* Verify if all the collection keys belong to the same parent
|
|
228
240
|
*/
|
|
@@ -251,7 +263,7 @@ declare function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge)
|
|
|
251
263
|
* @param mergeReplaceNullPatches Record where the key is a collection member key and the value is a list of
|
|
252
264
|
* tuples that we'll use to replace the nested objects of that collection member record with something else.
|
|
253
265
|
*/
|
|
254
|
-
declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase
|
|
266
|
+
declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey>, mergeReplaceNullPatches?: MultiMergeReplaceNullPatches, isProcessingCollectionUpdate?: boolean): Promise<void>;
|
|
255
267
|
/**
|
|
256
268
|
* Sets keys in a collection by replacing all targeted collection members with new values.
|
|
257
269
|
* Any existing collection members not included in the new data will not be removed.
|
|
@@ -259,7 +271,7 @@ declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase, TMap
|
|
|
259
271
|
* @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
|
|
260
272
|
* @param collection Object collection keyed by individual collection member keys and values
|
|
261
273
|
*/
|
|
262
|
-
declare function partialSetCollection<TKey extends CollectionKeyBase
|
|
274
|
+
declare function partialSetCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collection: OnyxSetCollectionInput<TKey>): Promise<void>;
|
|
263
275
|
declare function logKeyChanged(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey, value: unknown, hasChanged: boolean): void;
|
|
264
276
|
declare function logKeyRemoved(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey): void;
|
|
265
277
|
/**
|
|
@@ -324,6 +336,8 @@ declare const OnyxUtils: {
|
|
|
324
336
|
updateSnapshots: typeof updateSnapshots;
|
|
325
337
|
mergeCollectionWithPatches: typeof mergeCollectionWithPatches;
|
|
326
338
|
partialSetCollection: typeof partialSetCollection;
|
|
339
|
+
preserveCollectionReferences: typeof preserveCollectionReferences;
|
|
340
|
+
preserveCollectionReferencesAfterMerge: typeof preserveCollectionReferencesAfterMerge;
|
|
327
341
|
logKeyChanged: typeof logKeyChanged;
|
|
328
342
|
logKeyRemoved: typeof logKeyRemoved;
|
|
329
343
|
};
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -452,6 +452,51 @@ function tryGetCachedValue(key) {
|
|
|
452
452
|
}
|
|
453
453
|
return val;
|
|
454
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Utility function to preserve object references for unchanged items in collection operations.
|
|
457
|
+
* Compares new values with cached values using deep equality and preserves references when data is identical.
|
|
458
|
+
* @returns The preserved collection with unchanged references maintained
|
|
459
|
+
*/
|
|
460
|
+
function preserveCollectionReferences(keyValuePairs) {
|
|
461
|
+
const preservedCollection = {};
|
|
462
|
+
keyValuePairs.forEach(([key, value]) => {
|
|
463
|
+
const cachedValue = OnyxCache_1.default.get(key, false);
|
|
464
|
+
// If no cached value exists, we need to add the new value (skip expensive deep equality check)
|
|
465
|
+
// Use deep equality check to preserve references for unchanged items
|
|
466
|
+
if (cachedValue !== undefined && (0, fast_equals_1.deepEqual)(value, cachedValue)) {
|
|
467
|
+
// Keep the existing reference
|
|
468
|
+
preservedCollection[key] = cachedValue;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
// Update cache only for changed items
|
|
472
|
+
OnyxCache_1.default.set(key, value);
|
|
473
|
+
preservedCollection[key] = value;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
return preservedCollection;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Utility function for merge operations that preserves references after cache merge has been performed.
|
|
480
|
+
* Compares merged values with original cached values and preserves references when data is unchanged.
|
|
481
|
+
* @returns The preserved collection with unchanged references maintained
|
|
482
|
+
*/
|
|
483
|
+
function preserveCollectionReferencesAfterMerge(collection, originalCachedValues) {
|
|
484
|
+
const preservedCollection = {};
|
|
485
|
+
Object.keys(collection).forEach((key) => {
|
|
486
|
+
const newMergedValue = OnyxCache_1.default.get(key, false);
|
|
487
|
+
const originalValue = originalCachedValues[key];
|
|
488
|
+
// Use deep equality check to preserve references for unchanged items
|
|
489
|
+
if (originalValue !== undefined && (0, fast_equals_1.deepEqual)(newMergedValue, originalValue)) {
|
|
490
|
+
// Keep the existing reference and update cache
|
|
491
|
+
preservedCollection[key] = originalValue;
|
|
492
|
+
OnyxCache_1.default.set(key, originalValue);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
preservedCollection[key] = newMergedValue;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
return preservedCollection;
|
|
499
|
+
}
|
|
455
500
|
function getCachedCollection(collectionKey, collectionMemberKeys) {
|
|
456
501
|
// Use optimized collection data retrieval when cache is populated
|
|
457
502
|
const collectionData = OnyxCache_1.default.getCollectionData(collectionKey);
|
|
@@ -1094,10 +1139,18 @@ function mergeCollectionWithPatches(collectionKey, collection, mergeReplaceNullP
|
|
|
1094
1139
|
// finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
|
|
1095
1140
|
const finalMergedCollection = Object.assign(Object.assign({}, existingKeyCollection), newCollection);
|
|
1096
1141
|
// Prefill cache if necessary by calling get() on any existing keys and then merge original data to cache
|
|
1097
|
-
// and update all subscribers
|
|
1142
|
+
// and update all subscribers with reference preservation for unchanged items
|
|
1098
1143
|
const promiseUpdate = previousCollectionPromise.then((previousCollection) => {
|
|
1144
|
+
// Capture the original cached values before merging
|
|
1145
|
+
const originalCachedValues = {};
|
|
1146
|
+
Object.keys(finalMergedCollection).forEach((key) => {
|
|
1147
|
+
originalCachedValues[key] = OnyxCache_1.default.get(key, false);
|
|
1148
|
+
});
|
|
1149
|
+
// Then merge all the data into cache as normal
|
|
1099
1150
|
OnyxCache_1.default.merge(finalMergedCollection);
|
|
1100
|
-
|
|
1151
|
+
// Finally, preserve references for items that didn't actually change
|
|
1152
|
+
const preservedCollection = preserveCollectionReferencesAfterMerge(finalMergedCollection, originalCachedValues);
|
|
1153
|
+
return scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
|
|
1101
1154
|
});
|
|
1102
1155
|
return Promise.all(promises)
|
|
1103
1156
|
.catch((error) => evictStorageAndRetry(error, mergeCollectionWithPatches, collectionKey, resultCollection))
|
|
@@ -1145,8 +1198,9 @@ function partialSetCollection(collectionKey, collection) {
|
|
|
1145
1198
|
const existingKeys = resultCollectionKeys.filter((key) => persistedKeys.has(key));
|
|
1146
1199
|
const previousCollection = getCachedCollection(collectionKey, existingKeys);
|
|
1147
1200
|
const keyValuePairs = prepareKeyValuePairsForStorage(mutableCollection, true, undefined, true);
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1201
|
+
// Preserve references for unchanged items in partialSetCollection
|
|
1202
|
+
const preservedCollection = preserveCollectionReferences(keyValuePairs);
|
|
1203
|
+
const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, preservedCollection, previousCollection);
|
|
1150
1204
|
return storage_1.default.multiSet(keyValuePairs)
|
|
1151
1205
|
.catch((error) => evictStorageAndRetry(error, partialSetCollection, collectionKey, collection))
|
|
1152
1206
|
.then(() => {
|
|
@@ -1223,6 +1277,8 @@ const OnyxUtils = {
|
|
|
1223
1277
|
updateSnapshots,
|
|
1224
1278
|
mergeCollectionWithPatches,
|
|
1225
1279
|
partialSetCollection,
|
|
1280
|
+
preserveCollectionReferences,
|
|
1281
|
+
preserveCollectionReferencesAfterMerge,
|
|
1226
1282
|
logKeyChanged,
|
|
1227
1283
|
logKeyRemoved,
|
|
1228
1284
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ConnectOptions, OnyxUpdate } from './Onyx';
|
|
2
2
|
import Onyx from './Onyx';
|
|
3
|
-
import type { CustomTypeOptions, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput } from './types';
|
|
3
|
+
import type { CustomTypeOptions, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxSetCollectionInput } from './types';
|
|
4
4
|
import type { FetchStatus, ResultMetadata, UseOnyxResult, UseOnyxOptions } from './useOnyx';
|
|
5
5
|
import type { Connection } from './OnyxConnectionManager';
|
|
6
6
|
import useOnyx from './useOnyx';
|
|
7
7
|
import type { OnyxSQLiteKeyValuePair } from './storage/providers/SQLiteProvider';
|
|
8
8
|
export default Onyx;
|
|
9
9
|
export { useOnyx };
|
|
10
|
-
export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, Connection, UseOnyxOptions, OnyxSQLiteKeyValuePair, };
|
|
10
|
+
export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxSetCollectionInput, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, Connection, UseOnyxOptions, OnyxSQLiteKeyValuePair, };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Merge } from 'type-fest';
|
|
2
|
-
import type { BuiltIns } from 'type-fest/source/internal';
|
|
3
2
|
import type OnyxUtils from './OnyxUtils';
|
|
4
3
|
import type { OnyxMethod } from './OnyxUtils';
|
|
5
4
|
import type { FastMergeReplaceNullPatch } from './utils';
|
|
@@ -138,6 +137,8 @@ type KeyValueMapping = {
|
|
|
138
137
|
type OnyxValue<TKey extends OnyxKey> = string extends TKey ? unknown : TKey extends CollectionKeyBase ? OnyxCollection<KeyValueMapping[TKey]> : OnyxEntry<KeyValueMapping[TKey]>;
|
|
139
138
|
/** Utility type to extract `TOnyxValue` from `OnyxCollection<TOnyxValue>` */
|
|
140
139
|
type ExtractOnyxCollectionValue<TOnyxCollection> = TOnyxCollection extends NonNullable<OnyxCollection<infer U>> ? U : never;
|
|
140
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
141
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
141
142
|
type NonTransformableTypes = BuiltIns | ((...args: any[]) => unknown) | Map<unknown, unknown> | Set<unknown> | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | unknown[] | readonly unknown[];
|
|
142
143
|
/**
|
|
143
144
|
* Create a type from another type with all keys and nested keys set to optional or null.
|
|
@@ -174,8 +175,8 @@ type NullishObjectDeep<ObjectType extends object> = {
|
|
|
174
175
|
* Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
|
|
175
176
|
* the object of collection keys/values specified in the second parameter of the method.
|
|
176
177
|
*/
|
|
177
|
-
type Collection<TKey extends CollectionKeyBase, TValue
|
|
178
|
-
[
|
|
178
|
+
type Collection<TKey extends CollectionKeyBase, TValue> = Record<`${TKey}${string}`, TValue> & {
|
|
179
|
+
[P in TKey]?: never;
|
|
179
180
|
};
|
|
180
181
|
/** Represents the base options used in `Onyx.connect()` method. */
|
|
181
182
|
type BaseConnectOptions = {
|
|
@@ -263,44 +264,46 @@ type OnyxMergeInput<TKey extends OnyxKey> = OnyxInput<TKey>;
|
|
|
263
264
|
/**
|
|
264
265
|
* This represents the value that can be passed to `Onyx.merge` and to `Onyx.update` with the method "MERGE"
|
|
265
266
|
*/
|
|
266
|
-
type OnyxMergeCollectionInput<TKey extends OnyxKey
|
|
267
|
+
type OnyxMergeCollectionInput<TKey extends OnyxKey> = Collection<TKey, NonNullable<OnyxInput<TKey>>>;
|
|
268
|
+
/**
|
|
269
|
+
* This represents the value that can be passed to `Onyx.setCollection` and to `Onyx.update` with the method "SET_COLLECTION"
|
|
270
|
+
*/
|
|
271
|
+
type OnyxSetCollectionInput<TKey extends OnyxKey> = Collection<TKey, OnyxInput<TKey>>;
|
|
267
272
|
type OnyxMethodMap = typeof OnyxUtils.METHOD;
|
|
268
|
-
type OnyxMethodValueMap = {
|
|
269
|
-
[OnyxUtils.METHOD.SET]: {
|
|
270
|
-
key: OnyxKey;
|
|
271
|
-
value: OnyxSetInput<OnyxKey>;
|
|
272
|
-
};
|
|
273
|
-
[OnyxUtils.METHOD.MULTI_SET]: {
|
|
274
|
-
key: OnyxKey;
|
|
275
|
-
value: OnyxMultiSetInput;
|
|
276
|
-
};
|
|
277
|
-
[OnyxUtils.METHOD.MERGE]: {
|
|
278
|
-
key: OnyxKey;
|
|
279
|
-
value: OnyxMergeInput<OnyxKey>;
|
|
280
|
-
};
|
|
281
|
-
[OnyxUtils.METHOD.CLEAR]: {
|
|
282
|
-
key: OnyxKey;
|
|
283
|
-
value?: undefined;
|
|
284
|
-
};
|
|
285
|
-
[OnyxUtils.METHOD.MERGE_COLLECTION]: {
|
|
286
|
-
key: CollectionKeyBase;
|
|
287
|
-
value: OnyxMergeCollectionInput<CollectionKeyBase>;
|
|
288
|
-
};
|
|
289
|
-
[OnyxUtils.METHOD.SET_COLLECTION]: {
|
|
290
|
-
key: CollectionKeyBase;
|
|
291
|
-
value: OnyxMergeCollectionInput<CollectionKeyBase>;
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
273
|
/**
|
|
295
274
|
* OnyxUpdate type includes all onyx methods used in OnyxMethodValueMap.
|
|
296
275
|
* If a new method is added to OnyxUtils.METHOD constant, it must be added to OnyxMethodValueMap type.
|
|
297
276
|
* Otherwise it will show static type errors.
|
|
298
277
|
*/
|
|
299
278
|
type OnyxUpdate = {
|
|
300
|
-
[
|
|
301
|
-
onyxMethod:
|
|
302
|
-
|
|
303
|
-
|
|
279
|
+
[TKey in OnyxKey]: {
|
|
280
|
+
onyxMethod: typeof OnyxUtils.METHOD.SET;
|
|
281
|
+
key: TKey;
|
|
282
|
+
value: OnyxSetInput<TKey>;
|
|
283
|
+
} | {
|
|
284
|
+
onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
|
|
285
|
+
key: TKey;
|
|
286
|
+
value: OnyxMultiSetInput;
|
|
287
|
+
} | {
|
|
288
|
+
onyxMethod: typeof OnyxUtils.METHOD.MERGE;
|
|
289
|
+
key: TKey;
|
|
290
|
+
value: OnyxMergeInput<TKey>;
|
|
291
|
+
} | {
|
|
292
|
+
onyxMethod: typeof OnyxUtils.METHOD.CLEAR;
|
|
293
|
+
key: TKey;
|
|
294
|
+
value?: undefined;
|
|
295
|
+
};
|
|
296
|
+
}[OnyxKey] | {
|
|
297
|
+
[TKey in CollectionKeyBase]: {
|
|
298
|
+
onyxMethod: typeof OnyxUtils.METHOD.MERGE_COLLECTION;
|
|
299
|
+
key: TKey;
|
|
300
|
+
value: OnyxMergeCollectionInput<TKey>;
|
|
301
|
+
} | {
|
|
302
|
+
onyxMethod: typeof OnyxUtils.METHOD.SET_COLLECTION;
|
|
303
|
+
key: TKey;
|
|
304
|
+
value: OnyxSetCollectionInput<TKey>;
|
|
305
|
+
};
|
|
306
|
+
}[CollectionKeyBase];
|
|
304
307
|
/**
|
|
305
308
|
* Represents the options used in `Onyx.set()` method.
|
|
306
309
|
*/
|
|
@@ -365,4 +368,4 @@ type MixedOperationsQueue = {
|
|
|
365
368
|
mergeReplaceNullPatches: MultiMergeReplaceNullPatches;
|
|
366
369
|
set: OnyxInputKeyValueMapping;
|
|
367
370
|
};
|
|
368
|
-
export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, CallbackToStateMapping, NonNull, NonUndefined, OnyxInputKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxMethod, OnyxMethodMap, OnyxUpdate, OnyxValue, Selector, SetOptions, MultiMergeReplaceNullPatches, MixedOperationsQueue, };
|
|
371
|
+
export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, CallbackToStateMapping, NonNull, NonUndefined, OnyxInputKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxSetCollectionInput, OnyxMethod, OnyxMethodMap, OnyxUpdate, OnyxValue, Selector, SetOptions, MultiMergeReplaceNullPatches, MixedOperationsQueue, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-onyx",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"author": "Expensify, Inc.",
|
|
5
5
|
"homepage": "https://expensify.com",
|
|
6
6
|
"description": "State management for React Native",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"lint": "eslint .",
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
34
|
"test": "jest",
|
|
35
|
+
"test:types": "npm run build && tsc --noEmit --project tsconfig.test.json",
|
|
35
36
|
"perf-test": "npx reassure",
|
|
36
37
|
"build": "tsc -p tsconfig.build.json",
|
|
37
38
|
"build:watch": "nodemon --watch lib --ext js,json,ts,tsx --exec \"npm run build && npm pack\"",
|