react-native-onyx 2.0.81 → 2.0.82
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 +13 -20
- package/dist/OnyxUtils.d.ts +1 -0
- package/dist/types.d.ts +35 -26
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -515,7 +515,7 @@ function updateSnapshots(data) {
|
|
|
515
515
|
function update(data) {
|
|
516
516
|
// First, validate the Onyx object is in the format we expect
|
|
517
517
|
data.forEach(({ onyxMethod, key, value }) => {
|
|
518
|
-
if (!
|
|
518
|
+
if (!Object.values(OnyxUtils_1.default.METHOD).includes(onyxMethod)) {
|
|
519
519
|
throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
|
|
520
520
|
}
|
|
521
521
|
if (onyxMethod === OnyxUtils_1.default.METHOD.MULTI_SET) {
|
|
@@ -552,18 +552,14 @@ function update(data) {
|
|
|
552
552
|
const promises = [];
|
|
553
553
|
let clearPromise = Promise.resolve();
|
|
554
554
|
data.forEach(({ onyxMethod, key, value }) => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
case OnyxUtils_1.default.METHOD.MERGE:
|
|
560
|
-
enqueueMergeOperation(key, value);
|
|
561
|
-
break;
|
|
562
|
-
case OnyxUtils_1.default.METHOD.MERGE_COLLECTION: {
|
|
555
|
+
const handlers = {
|
|
556
|
+
[OnyxUtils_1.default.METHOD.SET]: enqueueSetOperation,
|
|
557
|
+
[OnyxUtils_1.default.METHOD.MERGE]: enqueueMergeOperation,
|
|
558
|
+
[OnyxUtils_1.default.METHOD.MERGE_COLLECTION]: () => {
|
|
563
559
|
const collection = value;
|
|
564
560
|
if (!OnyxUtils_1.default.isValidNonEmptyCollectionForMerge(collection)) {
|
|
565
561
|
Logger.logInfo('mergeCollection enqueued within update() with invalid or empty value. Skipping this operation.');
|
|
566
|
-
|
|
562
|
+
return;
|
|
567
563
|
}
|
|
568
564
|
// Confirm all the collection keys belong to the same parent
|
|
569
565
|
const collectionKeys = Object.keys(collection);
|
|
@@ -571,17 +567,14 @@ function update(data) {
|
|
|
571
567
|
const mergedCollection = collection;
|
|
572
568
|
collectionKeys.forEach((collectionKey) => enqueueMergeOperation(collectionKey, mergedCollection[collectionKey]));
|
|
573
569
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
break;
|
|
579
|
-
case OnyxUtils_1.default.METHOD.CLEAR:
|
|
570
|
+
},
|
|
571
|
+
[OnyxUtils_1.default.METHOD.SET_COLLECTION]: (k, v) => promises.push(() => setCollection(k, v)),
|
|
572
|
+
[OnyxUtils_1.default.METHOD.MULTI_SET]: (k, v) => Object.entries(v).forEach(([entryKey, entryValue]) => enqueueSetOperation(entryKey, entryValue)),
|
|
573
|
+
[OnyxUtils_1.default.METHOD.CLEAR]: () => {
|
|
580
574
|
clearPromise = clear();
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
handlers[onyxMethod](key, value);
|
|
585
578
|
});
|
|
586
579
|
// Group all the collection-related keys and update each collection in a single `mergeCollection` call.
|
|
587
580
|
// This is needed to prevent multiple `mergeCollection` calls for the same collection and `merge` calls for the individual items of the said collection.
|
package/dist/OnyxUtils.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Merge } from 'type-fest';
|
|
|
2
2
|
import type { BuiltIns } from 'type-fest/source/internal';
|
|
3
3
|
import type OnyxUtils from './OnyxUtils';
|
|
4
4
|
import type { WithOnyxInstance, WithOnyxState } from './withOnyx/types';
|
|
5
|
+
import type { OnyxMethod } from './OnyxUtils';
|
|
5
6
|
/**
|
|
6
7
|
* Utility type that excludes `null` from the type `TValue`.
|
|
7
8
|
*/
|
|
@@ -329,35 +330,43 @@ type OnyxMergeInput<TKey extends OnyxKey> = OnyxInput<TKey>;
|
|
|
329
330
|
* This represents the value that can be passed to `Onyx.merge` and to `Onyx.update` with the method "MERGE"
|
|
330
331
|
*/
|
|
331
332
|
type OnyxMergeCollectionInput<TKey extends OnyxKey, TMap = object> = Collection<TKey, NonNullable<OnyxInput<TKey>>, TMap>;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
key:
|
|
340
|
-
value: OnyxSetInput<TKey>;
|
|
341
|
-
} | {
|
|
342
|
-
onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
|
|
343
|
-
key: TKey;
|
|
333
|
+
type OnyxMethodMap = typeof OnyxUtils.METHOD;
|
|
334
|
+
type OnyxMethodValueMap = {
|
|
335
|
+
[OnyxUtils.METHOD.SET]: {
|
|
336
|
+
key: OnyxKey;
|
|
337
|
+
value: OnyxSetInput<OnyxKey>;
|
|
338
|
+
};
|
|
339
|
+
[OnyxUtils.METHOD.MULTI_SET]: {
|
|
340
|
+
key: OnyxKey;
|
|
344
341
|
value: OnyxMultiSetInput;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
key:
|
|
348
|
-
value: OnyxMergeInput<
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
key:
|
|
342
|
+
};
|
|
343
|
+
[OnyxUtils.METHOD.MERGE]: {
|
|
344
|
+
key: OnyxKey;
|
|
345
|
+
value: OnyxMergeInput<OnyxKey>;
|
|
346
|
+
};
|
|
347
|
+
[OnyxUtils.METHOD.CLEAR]: {
|
|
348
|
+
key: OnyxKey;
|
|
352
349
|
value?: undefined;
|
|
353
350
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
key: TKey;
|
|
358
|
-
value: OnyxMergeCollectionInput<TKey>;
|
|
351
|
+
[OnyxUtils.METHOD.MERGE_COLLECTION]: {
|
|
352
|
+
key: CollectionKeyBase;
|
|
353
|
+
value: OnyxMergeCollectionInput<CollectionKeyBase>;
|
|
359
354
|
};
|
|
360
|
-
|
|
355
|
+
[OnyxUtils.METHOD.SET_COLLECTION]: {
|
|
356
|
+
key: CollectionKeyBase;
|
|
357
|
+
value: OnyxMergeCollectionInput<CollectionKeyBase>;
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* OnyxUpdate type includes all onyx methods used in OnyxMethodValueMap.
|
|
362
|
+
* If a new method is added to OnyxUtils.METHOD constant, it must be added to OnyxMethodValueMap type.
|
|
363
|
+
* Otherwise it will show static type errors.
|
|
364
|
+
*/
|
|
365
|
+
type OnyxUpdate = {
|
|
366
|
+
[Method in OnyxMethod]: {
|
|
367
|
+
onyxMethod: Method;
|
|
368
|
+
} & OnyxMethodValueMap[Method];
|
|
369
|
+
}[OnyxMethod];
|
|
361
370
|
/**
|
|
362
371
|
* Represents the options used in `Onyx.init()` method.
|
|
363
372
|
*/
|
|
@@ -393,4 +402,4 @@ type MixedOperationsQueue = {
|
|
|
393
402
|
merge: OnyxInputKeyValueMapping;
|
|
394
403
|
set: OnyxInputKeyValueMapping;
|
|
395
404
|
};
|
|
396
|
-
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, OnyxUpdate, OnyxValue, Selector, WithOnyxConnectOptions, MixedOperationsQueue, };
|
|
405
|
+
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, MixedOperationsQueue, };
|