react-native-onyx 3.0.19 → 3.0.21
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 +1 -1
- package/dist/OnyxUtils.d.ts +1 -1
- package/dist/types.d.ts +17 -20
- package/dist/useOnyx.js +6 -4
- package/package.json +1 -1
package/dist/Onyx.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
|
|
|
139
139
|
* @param data An array of objects with update expressions
|
|
140
140
|
* @returns resolves when all operations are complete
|
|
141
141
|
*/
|
|
142
|
-
declare function update(data: OnyxUpdate
|
|
142
|
+
declare function update<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>): Promise<void>;
|
|
143
143
|
/**
|
|
144
144
|
* Sets a collection by replacing all existing collection members with new values.
|
|
145
145
|
* Any existing collection members not included in the new data will be removed.
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -241,7 +241,7 @@ declare function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOpt
|
|
|
241
241
|
* @param subscriptionID Subscription ID returned by calling `OnyxUtils.subscribeToKey()`.
|
|
242
242
|
*/
|
|
243
243
|
declare function unsubscribeFromKey(subscriptionID: number): void;
|
|
244
|
-
declare function updateSnapshots(data: OnyxUpdate
|
|
244
|
+
declare function updateSnapshots<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>, mergeFn: typeof Onyx.merge): Array<() => Promise<void>>;
|
|
245
245
|
/**
|
|
246
246
|
* Writes a value to our store with the given key.
|
|
247
247
|
* Serves as core implementation for `Onyx.set()` public function, the difference being
|
package/dist/types.d.ts
CHANGED
|
@@ -175,9 +175,7 @@ type NullishObjectDeep<ObjectType extends object> = {
|
|
|
175
175
|
* Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
|
|
176
176
|
* the object of collection keys/values specified in the second parameter of the method.
|
|
177
177
|
*/
|
|
178
|
-
type Collection<TKey extends CollectionKeyBase, TValue> = Record<`${TKey}${string}`, TValue
|
|
179
|
-
[P in TKey]?: never;
|
|
180
|
-
};
|
|
178
|
+
type Collection<TKey extends CollectionKeyBase, TValue> = Record<`${TKey}${string}`, TValue>;
|
|
181
179
|
/** Represents the base options used in `Onyx.connect()` method. */
|
|
182
180
|
type BaseConnectOptions = {
|
|
183
181
|
/** If set to `false`, then the initial data will be only sent to the callback function if it changes. */
|
|
@@ -270,40 +268,39 @@ type OnyxMergeCollectionInput<TKey extends OnyxKey> = Collection<TKey, NonNullab
|
|
|
270
268
|
*/
|
|
271
269
|
type OnyxSetCollectionInput<TKey extends OnyxKey> = Collection<TKey, OnyxInput<TKey>>;
|
|
272
270
|
type OnyxMethodMap = typeof OnyxUtils.METHOD;
|
|
271
|
+
type ExpandOnyxKeys<TKey extends OnyxKey> = TKey extends CollectionKeyBase ? NoInfer<`${TKey}${string}`> : TKey;
|
|
273
272
|
/**
|
|
274
273
|
* OnyxUpdate type includes all onyx methods used in OnyxMethodValueMap.
|
|
275
274
|
* If a new method is added to OnyxUtils.METHOD constant, it must be added to OnyxMethodValueMap type.
|
|
276
275
|
* Otherwise it will show static type errors.
|
|
277
276
|
*/
|
|
278
|
-
type OnyxUpdate = {
|
|
279
|
-
[
|
|
277
|
+
type OnyxUpdate<TKey extends OnyxKey = OnyxKey> = {
|
|
278
|
+
[K in TKey]: {
|
|
280
279
|
onyxMethod: typeof OnyxUtils.METHOD.SET;
|
|
281
|
-
key:
|
|
282
|
-
value: OnyxSetInput<
|
|
280
|
+
key: ExpandOnyxKeys<K>;
|
|
281
|
+
value: OnyxSetInput<K>;
|
|
283
282
|
} | {
|
|
284
283
|
onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
|
|
285
|
-
key:
|
|
284
|
+
key: ExpandOnyxKeys<K>;
|
|
286
285
|
value: OnyxMultiSetInput;
|
|
287
286
|
} | {
|
|
288
287
|
onyxMethod: typeof OnyxUtils.METHOD.MERGE;
|
|
289
|
-
key:
|
|
290
|
-
value: OnyxMergeInput<
|
|
288
|
+
key: ExpandOnyxKeys<K>;
|
|
289
|
+
value: OnyxMergeInput<K>;
|
|
291
290
|
} | {
|
|
292
291
|
onyxMethod: typeof OnyxUtils.METHOD.CLEAR;
|
|
293
|
-
key:
|
|
294
|
-
value?:
|
|
295
|
-
}
|
|
296
|
-
}[OnyxKey] | {
|
|
297
|
-
[TKey in CollectionKeyBase]: {
|
|
292
|
+
key: ExpandOnyxKeys<K>;
|
|
293
|
+
value?: never;
|
|
294
|
+
} | {
|
|
298
295
|
onyxMethod: typeof OnyxUtils.METHOD.MERGE_COLLECTION;
|
|
299
|
-
key:
|
|
300
|
-
value: OnyxMergeCollectionInput<
|
|
296
|
+
key: K;
|
|
297
|
+
value: OnyxMergeCollectionInput<K>;
|
|
301
298
|
} | {
|
|
302
299
|
onyxMethod: typeof OnyxUtils.METHOD.SET_COLLECTION;
|
|
303
|
-
key:
|
|
304
|
-
value: OnyxSetCollectionInput<
|
|
300
|
+
key: K;
|
|
301
|
+
value: OnyxSetCollectionInput<K>;
|
|
305
302
|
};
|
|
306
|
-
}[
|
|
303
|
+
}[TKey];
|
|
307
304
|
/**
|
|
308
305
|
* Represents the options used in `Onyx.set()` method.
|
|
309
306
|
*/
|
package/dist/useOnyx.js
CHANGED
|
@@ -234,22 +234,24 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
234
234
|
if (shouldUpdateResult) {
|
|
235
235
|
previousValueRef.current = newValueRef.current;
|
|
236
236
|
// If the new value is `null` we default it to `undefined` to ensure the consumer gets a consistent result from the hook.
|
|
237
|
-
|
|
237
|
+
newFetchStatus = newFetchStatus !== null && newFetchStatus !== void 0 ? newFetchStatus : 'loaded';
|
|
238
238
|
resultRef.current = [
|
|
239
239
|
(_d = previousValueRef.current) !== null && _d !== void 0 ? _d : undefined,
|
|
240
240
|
{
|
|
241
|
-
status:
|
|
241
|
+
status: newFetchStatus,
|
|
242
242
|
sourceValue: sourceValueRef.current,
|
|
243
243
|
},
|
|
244
244
|
];
|
|
245
245
|
// If `canBeMissing` is set to `false` and the Onyx value of that key is not defined,
|
|
246
246
|
// we log an alert so it can be acknowledged by the consumer. Additionally, we won't log alerts
|
|
247
247
|
// if there's a `Onyx.clear()` task in progress.
|
|
248
|
-
if ((options === null || options === void 0 ? void 0 : options.canBeMissing) === false &&
|
|
248
|
+
if ((options === null || options === void 0 ? void 0 : options.canBeMissing) === false && newFetchStatus === 'loaded' && !isOnyxValueDefined && !OnyxCache_1.default.hasPendingTask(OnyxCache_1.TASK.CLEAR)) {
|
|
249
249
|
Logger.logAlert(`useOnyx returned no data for key with canBeMissing set to false for key ${key}`, { showAlert: true });
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
if (newFetchStatus !== 'loading') {
|
|
253
|
+
OnyxSnapshotCache_1.default.setCachedResult(key, cacheKey, resultRef.current);
|
|
254
|
+
}
|
|
253
255
|
return resultRef.current;
|
|
254
256
|
}, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, memoizedSelector, cacheKey]);
|
|
255
257
|
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
|