Skip to content

Commit 500d228

Browse files
committed
Address review comments
1 parent 86aa549 commit 500d228

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/Onyx.d.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ type BaseConnectOptions = {
3434
* The type is built from `BaseConnectOptions` and extended to handle key/callback related options.
3535
* It includes two different forms, depending on whether we are waiting for a collection callback or not.
3636
*
37-
* If `waitForCollectionCallback` is `true`, it expects `key` to be a Onyx collection key and `callback` will pass `value` as an `OnyxCollection`.
37+
* If `waitForCollectionCallback` is `true`, it expects `key` to be a Onyx collection key and `callback` will be triggered with the whole collection
38+
* and will pass `value` as an `OnyxCollection`.
3839
*
39-
* If `waitForCollectionCallback` is `false` or not specified, the `key` can be any Onyx key and `callback` will pass `value` as an `OnyxEntry`.
40+
*
41+
* If `waitForCollectionCallback` is `false` or not specified, the `key` can be any Onyx key and `callback` will be triggered with updates of each collection item
42+
* and will pass `value` as an `OnyxEntry`.
4043
*/
4144
type ConnectOptions<TKey extends OnyxKey> = BaseConnectOptions &
4245
(
@@ -54,8 +57,12 @@ type ConnectOptions<TKey extends OnyxKey> = BaseConnectOptions &
5457

5558
/**
5659
* Represents a mapping between Onyx collection keys and their respective values.
60+
*
5761
* It helps to enforce that a Onyx collection key should not be without suffix (e.g. should always be of the form `${TKey}${string}`),
5862
* and to map each Onyx collection key with suffix to a value of type `TValue`.
63+
*
64+
* Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
65+
* the object of collection keys/values specified in the second parameter of the method.
5966
*/
6067
type Collection<TKey extends CollectionKeyBase, TMap, TValue> = {
6168
[MapK in keyof TMap]: MapK extends `${TKey}${string}`
@@ -95,7 +102,7 @@ type OnyxUpdate =
95102
* Represents the options used in `Onyx.init()` method.
96103
*/
97104
type InitOptions = {
98-
keys?: DeepRecord<string, string>;
105+
keys?: DeepRecord<string, OnyxKey>;
99106
initialKeyStates?: Partial<NullableKeyValueMapping>;
100107
safeEvictionKeys?: OnyxKey[];
101108
maxCachedKeysCount?: number;
@@ -231,6 +238,10 @@ declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
231238
/**
232239
* Merges a collection based on their keys
233240
*
241+
* Note that both `TKey` and `TMap` types are inferred automatically, `TKey` being the
242+
* collection key specified in the first parameter and `TMap` being the object of
243+
* collection keys/values specified in the second parameter.
244+
*
234245
* @example
235246
*
236247
* Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
@@ -249,7 +260,7 @@ declare function mergeCollection<TKey extends CollectionKeyBase, TMap>(
249260
/**
250261
* Insert API responses and lifecycle data into Onyx
251262
*
252-
* @param data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *}
263+
* @param data An array of update objects
253264
* @returns resolves when all operations are complete
254265
*/
255266
declare function update(data: OnyxUpdate[]): Promise<void>;

lib/types.d.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,8 @@ type KeyValueMapping = {
119119
*
120120
* The type `TKey` extends `OnyxKey` and it is the key used to access a value in `KeyValueMapping`.
121121
* `TReturnType` is the type of the returned value from the selector function.
122-
*
123-
* If `KeyValueMapping[TKey]` is equal to 'unknown', the `Selector` type represents a function
124-
* that takes any value and returns an `unknown` value.
125-
*
126-
* If `KeyValueMapping[TKey]` is not 'unknown', the `Selector` type represents a function that
127-
* takes either the value of type `OnyxEntry<KeyValueMapping[TKey]>`, and returns a value of `TReturnType`.
128122
*/
129-
type Selector<TKey extends OnyxKey, TReturnType> = IsEqual<KeyValueMapping[TKey], unknown> extends true
130-
? (value: unknown) => unknown
131-
: (value: OnyxEntry<KeyValueMapping[TKey]>) => TReturnType;
123+
type Selector<TKey extends OnyxKey, TReturnType> = (value: OnyxEntry<KeyValueMapping[TKey]>) => TReturnType;
132124

133125
/**
134126
* Represents a single Onyx entry, that can be either `TOnyxValue` or `null` if it doesn't exist.

0 commit comments

Comments
 (0)