react-native-onyx 2.0.27 → 2.0.29
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/API.md +85 -327
- package/dist/DevTools.d.ts +1 -1
- package/dist/Onyx.d.ts +7 -7
- package/dist/Onyx.js +21 -14
- package/dist/OnyxUtils.d.ts +107 -189
- package/dist/OnyxUtils.js +102 -264
- package/dist/PerformanceUtils.js +1 -1
- package/dist/storage/providers/NoopProvider.js +1 -3
- package/dist/storage/providers/types.d.ts +2 -2
- package/dist/types.d.ts +29 -17
- package/dist/useOnyx.js +1 -1
- package/package.json +8 -2
package/API.md
CHANGED
|
@@ -1,70 +1,26 @@
|
|
|
1
|
-
<!---These docs were automatically generated. Do not edit them directly run `npm run build
|
|
1
|
+
<!---These docs were automatically generated. Do not edit them directly run `npm run build:docs` script-->
|
|
2
2
|
|
|
3
3
|
# API Reference
|
|
4
4
|
|
|
5
5
|
## Functions
|
|
6
6
|
|
|
7
7
|
<dl>
|
|
8
|
-
<dt><a href="#
|
|
9
|
-
<dd><p>
|
|
10
|
-
</dd>
|
|
11
|
-
<dt><a href="#maybeFlushBatchUpdates">maybeFlushBatchUpdates()</a> ⇒ <code>Promise</code></dt>
|
|
12
|
-
<dd><p>We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other.
|
|
13
|
-
This happens for example in the Onyx.update function, where we process API responses that might contain a lot of
|
|
14
|
-
update operations. Instead of calling the subscribers for each update operation, we batch them together which will
|
|
15
|
-
cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization.</p>
|
|
16
|
-
</dd>
|
|
17
|
-
<dt><a href="#getSubsetOfData">getSubsetOfData(sourceData, selector, [withOnyxInstanceState])</a> ⇒ <code>Mixed</code></dt>
|
|
18
|
-
<dd><p>Uses a selector function to return a simplified version of sourceData</p>
|
|
19
|
-
</dd>
|
|
20
|
-
<dt><a href="#reduceCollectionWithSelector">reduceCollectionWithSelector(collection, selector, [withOnyxInstanceState])</a> ⇒ <code>Object</code></dt>
|
|
21
|
-
<dd><p>Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
|
|
22
|
-
and runs it through a reducer function to return a subset of the data according to a selector.
|
|
23
|
-
The resulting collection will only contain items that are returned by the selector.</p>
|
|
24
|
-
</dd>
|
|
25
|
-
<dt><a href="#isCollectionKey">isCollectionKey(key)</a> ⇒ <code>Boolean</code></dt>
|
|
26
|
-
<dd><p>Checks to see if the a subscriber's supplied key
|
|
27
|
-
is associated with a collection of keys.</p>
|
|
28
|
-
</dd>
|
|
29
|
-
<dt><a href="#isCollectionMemberKey">isCollectionMemberKey(collectionKey, key)</a> ⇒ <code>Boolean</code></dt>
|
|
30
|
-
<dd></dd>
|
|
31
|
-
<dt><a href="#splitCollectionMemberKey">splitCollectionMemberKey(key)</a> ⇒ <code>Array.<String></code></dt>
|
|
32
|
-
<dd><p>Splits a collection member key into the collection key part and the ID part.</p>
|
|
33
|
-
</dd>
|
|
34
|
-
<dt><a href="#tryGetCachedValue">tryGetCachedValue(key, mapping)</a> ⇒ <code>Mixed</code></dt>
|
|
35
|
-
<dd><p>Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
36
|
-
If the requested key is a collection, it will return an object with all the collection members.</p>
|
|
8
|
+
<dt><a href="#init">init()</a></dt>
|
|
9
|
+
<dd><p>Initialize the store with actions and listening for storage events</p>
|
|
37
10
|
</dd>
|
|
38
|
-
<dt><a href="#connect">connect(mapping)</a>
|
|
11
|
+
<dt><a href="#connect">connect(mapping)</a> ⇒</dt>
|
|
39
12
|
<dd><p>Subscribes a react component's state directly to a store key</p>
|
|
40
13
|
</dd>
|
|
41
|
-
<dt><a href="#disconnect">disconnect(connectionID
|
|
14
|
+
<dt><a href="#disconnect">disconnect(connectionID)</a></dt>
|
|
42
15
|
<dd><p>Remove the listener for a react component</p>
|
|
43
16
|
</dd>
|
|
44
|
-
<dt><a href="#
|
|
45
|
-
<dd><p>Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).</p>
|
|
46
|
-
</dd>
|
|
47
|
-
<dt><a href="#scheduleNotifyCollectionSubscribers">scheduleNotifyCollectionSubscribers(key, value)</a> ⇒ <code>Promise</code></dt>
|
|
48
|
-
<dd><p>This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections
|
|
49
|
-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
|
|
50
|
-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.</p>
|
|
51
|
-
</dd>
|
|
52
|
-
<dt><a href="#broadcastUpdate">broadcastUpdate(key, value, hasChanged, wasRemoved)</a> ⇒ <code>Promise</code></dt>
|
|
53
|
-
<dd><p>Notifys subscribers and writes current value to cache</p>
|
|
54
|
-
</dd>
|
|
55
|
-
<dt><a href="#hasPendingMergeForKey">hasPendingMergeForKey(key)</a> ⇒ <code>Boolean</code></dt>
|
|
56
|
-
<dd></dd>
|
|
57
|
-
<dt><a href="#removeNullValues">removeNullValues(key, value)</a> ⇒ <code>Mixed</code></dt>
|
|
58
|
-
<dd><p>Removes a key from storage if the value is null.
|
|
59
|
-
Otherwise removes all nested null values in objects and returns the object</p>
|
|
60
|
-
</dd>
|
|
61
|
-
<dt><a href="#set">set(key, value)</a> ⇒ <code>Promise</code></dt>
|
|
17
|
+
<dt><a href="#set">set(key, value)</a></dt>
|
|
62
18
|
<dd><p>Write a value to our store with the given key</p>
|
|
63
19
|
</dd>
|
|
64
|
-
<dt><a href="#multiSet">multiSet(data)</a
|
|
20
|
+
<dt><a href="#multiSet">multiSet(data)</a></dt>
|
|
65
21
|
<dd><p>Sets multiple keys and values</p>
|
|
66
22
|
</dd>
|
|
67
|
-
<dt><a href="#merge">merge(
|
|
23
|
+
<dt><a href="#merge">merge()</a></dt>
|
|
68
24
|
<dd><p>Merge a new value into an existing value at a key.</p>
|
|
69
25
|
<p>The types of values that can be merged are <code>Object</code> and <code>Array</code>. To set another type of value use <code>Onyx.set()</code>.
|
|
70
26
|
Values of type <code>Object</code> get merged with the old value, whilst for <code>Array</code>'s we simply replace the current value with the new one.</p>
|
|
@@ -72,7 +28,10 @@ Values of type <code>Object</code> get merged with the old value, whilst for <co
|
|
|
72
28
|
applied in the order they were called. Note: <code>Onyx.set()</code> calls do not work this way so use caution when mixing
|
|
73
29
|
<code>Onyx.merge()</code> and <code>Onyx.set()</code>.</p>
|
|
74
30
|
</dd>
|
|
75
|
-
<dt><a href="#
|
|
31
|
+
<dt><a href="#mergeCollection">mergeCollection(collectionKey, collection)</a></dt>
|
|
32
|
+
<dd><p>Merges a collection based on their keys</p>
|
|
33
|
+
</dd>
|
|
34
|
+
<dt><a href="#clear">clear(keysToPreserve)</a></dt>
|
|
76
35
|
<dd><p>Clear out all the data in the store</p>
|
|
77
36
|
<p>Note that calling Onyx.clear() and then Onyx.set() on a key with a default
|
|
78
37
|
key state may store an unexpected value in Storage.</p>
|
|
@@ -88,136 +47,38 @@ Onyx.get(key) before calling Storage.setItem() via Onyx.set().
|
|
|
88
47
|
Storage.setItem() from Onyx.clear() will have already finished and the merged
|
|
89
48
|
value will be saved to storage after the default value.</p>
|
|
90
49
|
</dd>
|
|
91
|
-
<dt><a href="#
|
|
92
|
-
<dd><p>Merges a collection based on their keys</p>
|
|
93
|
-
</dd>
|
|
94
|
-
<dt><a href="#update">update(data)</a> ⇒ <code>Promise</code></dt>
|
|
50
|
+
<dt><a href="#update">update(data)</a> ⇒</dt>
|
|
95
51
|
<dd><p>Insert API responses and lifecycle data into Onyx</p>
|
|
96
52
|
</dd>
|
|
97
|
-
<dt><a href="#init">init([options])</a></dt>
|
|
98
|
-
<dd><p>Initialize the store with actions and listening for storage events</p>
|
|
99
|
-
</dd>
|
|
100
53
|
</dl>
|
|
101
54
|
|
|
102
|
-
<a name="
|
|
103
|
-
|
|
104
|
-
## sendActionToDevTools(method, key, value, mergedValue)
|
|
105
|
-
Sends an action to DevTools extension
|
|
106
|
-
|
|
107
|
-
**Kind**: global function
|
|
108
|
-
|
|
109
|
-
| Param | Type | Description |
|
|
110
|
-
| --- | --- | --- |
|
|
111
|
-
| method | <code>string</code> | Onyx method from METHOD |
|
|
112
|
-
| key | <code>string</code> | Onyx key that was changed |
|
|
113
|
-
| value | <code>any</code> | contains the change that was made by the method |
|
|
114
|
-
| mergedValue | <code>any</code> | (optional) value that was written in the storage after a merge method was executed. |
|
|
115
|
-
|
|
116
|
-
<a name="maybeFlushBatchUpdates"></a>
|
|
117
|
-
|
|
118
|
-
## maybeFlushBatchUpdates() ⇒ <code>Promise</code>
|
|
119
|
-
We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other.
|
|
120
|
-
This happens for example in the Onyx.update function, where we process API responses that might contain a lot of
|
|
121
|
-
update operations. Instead of calling the subscribers for each update operation, we batch them together which will
|
|
122
|
-
cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization.
|
|
123
|
-
|
|
124
|
-
**Kind**: global function
|
|
125
|
-
<a name="getSubsetOfData"></a>
|
|
126
|
-
|
|
127
|
-
## getSubsetOfData(sourceData, selector, [withOnyxInstanceState]) ⇒ <code>Mixed</code>
|
|
128
|
-
Uses a selector function to return a simplified version of sourceData
|
|
129
|
-
|
|
130
|
-
**Kind**: global function
|
|
131
|
-
|
|
132
|
-
| Param | Type | Description |
|
|
133
|
-
| --- | --- | --- |
|
|
134
|
-
| sourceData | <code>Mixed</code> | |
|
|
135
|
-
| selector | <code>function</code> | Function that takes sourceData and returns a simplified version of it |
|
|
136
|
-
| [withOnyxInstanceState] | <code>Object</code> | |
|
|
137
|
-
|
|
138
|
-
<a name="reduceCollectionWithSelector"></a>
|
|
139
|
-
|
|
140
|
-
## reduceCollectionWithSelector(collection, selector, [withOnyxInstanceState]) ⇒ <code>Object</code>
|
|
141
|
-
Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
|
|
142
|
-
and runs it through a reducer function to return a subset of the data according to a selector.
|
|
143
|
-
The resulting collection will only contain items that are returned by the selector.
|
|
144
|
-
|
|
145
|
-
**Kind**: global function
|
|
146
|
-
|
|
147
|
-
| Param | Type | Description |
|
|
148
|
-
| --- | --- | --- |
|
|
149
|
-
| collection | <code>Object</code> | |
|
|
150
|
-
| selector | <code>String</code> \| <code>function</code> | (see method docs for getSubsetOfData() for full details) |
|
|
151
|
-
| [withOnyxInstanceState] | <code>Object</code> | |
|
|
152
|
-
|
|
153
|
-
<a name="isCollectionKey"></a>
|
|
154
|
-
|
|
155
|
-
## isCollectionKey(key) ⇒ <code>Boolean</code>
|
|
156
|
-
Checks to see if the a subscriber's supplied key
|
|
157
|
-
is associated with a collection of keys.
|
|
158
|
-
|
|
159
|
-
**Kind**: global function
|
|
160
|
-
|
|
161
|
-
| Param | Type |
|
|
162
|
-
| --- | --- |
|
|
163
|
-
| key | <code>String</code> |
|
|
164
|
-
|
|
165
|
-
<a name="isCollectionMemberKey"></a>
|
|
166
|
-
|
|
167
|
-
## isCollectionMemberKey(collectionKey, key) ⇒ <code>Boolean</code>
|
|
168
|
-
**Kind**: global function
|
|
169
|
-
|
|
170
|
-
| Param | Type |
|
|
171
|
-
| --- | --- |
|
|
172
|
-
| collectionKey | <code>String</code> |
|
|
173
|
-
| key | <code>String</code> |
|
|
174
|
-
|
|
175
|
-
<a name="splitCollectionMemberKey"></a>
|
|
176
|
-
|
|
177
|
-
## splitCollectionMemberKey(key) ⇒ <code>Array.<String></code>
|
|
178
|
-
Splits a collection member key into the collection key part and the ID part.
|
|
179
|
-
|
|
180
|
-
**Kind**: global function
|
|
181
|
-
**Returns**: <code>Array.<String></code> - A tuple where the first element is the collection part and the second element is the ID part.
|
|
182
|
-
|
|
183
|
-
| Param | Type | Description |
|
|
184
|
-
| --- | --- | --- |
|
|
185
|
-
| key | <code>String</code> | The collection member key to split. |
|
|
186
|
-
|
|
187
|
-
<a name="tryGetCachedValue"></a>
|
|
188
|
-
|
|
189
|
-
## tryGetCachedValue(key, mapping) ⇒ <code>Mixed</code>
|
|
190
|
-
Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
191
|
-
If the requested key is a collection, it will return an object with all the collection members.
|
|
192
|
-
|
|
193
|
-
**Kind**: global function
|
|
55
|
+
<a name="init"></a>
|
|
194
56
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
| key | <code>String</code> |
|
|
198
|
-
| mapping | <code>Object</code> |
|
|
57
|
+
## init()
|
|
58
|
+
Initialize the store with actions and listening for storage events
|
|
199
59
|
|
|
60
|
+
**Kind**: global function
|
|
200
61
|
<a name="connect"></a>
|
|
201
62
|
|
|
202
|
-
## connect(mapping) ⇒
|
|
63
|
+
## connect(mapping) ⇒
|
|
203
64
|
Subscribes a react component's state directly to a store key
|
|
204
65
|
|
|
205
|
-
**Kind**: global function
|
|
206
|
-
**Returns**:
|
|
207
|
-
|
|
208
|
-
| Param |
|
|
209
|
-
| --- | --- |
|
|
210
|
-
| mapping |
|
|
211
|
-
| mapping.key |
|
|
212
|
-
| [mapping.statePropertyName] |
|
|
213
|
-
| [mapping.withOnyxInstance] |
|
|
214
|
-
| [mapping.callback] |
|
|
215
|
-
| [mapping.initWithStoredValues] |
|
|
216
|
-
| [mapping.waitForCollectionCallback] |
|
|
217
|
-
| [mapping.selector] |
|
|
218
|
-
| [mapping.initialValue] |
|
|
219
|
-
|
|
220
|
-
**Example**
|
|
66
|
+
**Kind**: global function
|
|
67
|
+
**Returns**: an ID to use when calling disconnect
|
|
68
|
+
|
|
69
|
+
| Param | Description |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| mapping | the mapping information to connect Onyx to the components state |
|
|
72
|
+
| mapping.key | ONYXKEY to subscribe to |
|
|
73
|
+
| [mapping.statePropertyName] | the name of the property in the state to connect the data to |
|
|
74
|
+
| [mapping.withOnyxInstance] | whose setState() method will be called with any changed data This is used by React components to connect to Onyx |
|
|
75
|
+
| [mapping.callback] | a method that will be called with changed data This is used by any non-React code to connect to Onyx |
|
|
76
|
+
| [mapping.initWithStoredValues] | If set to false, then no data will be prefilled into the component |
|
|
77
|
+
| [mapping.waitForCollectionCallback] | If set to true, it will return the entire collection to the callback as a single object |
|
|
78
|
+
| [mapping.selector] | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. The sourceData and withOnyx state are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). |
|
|
79
|
+
| [mapping.initialValue] | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be passed to the component so that something can be rendered while data is being fetched from the DB. Note that it will not cause the component to have the loading prop set to true. |
|
|
80
|
+
|
|
81
|
+
**Example**
|
|
221
82
|
```js
|
|
222
83
|
const connectionID = Onyx.connect({
|
|
223
84
|
key: ONYXKEYS.SESSION,
|
|
@@ -226,119 +87,49 @@ const connectionID = Onyx.connect({
|
|
|
226
87
|
```
|
|
227
88
|
<a name="disconnect"></a>
|
|
228
89
|
|
|
229
|
-
## disconnect(connectionID
|
|
90
|
+
## disconnect(connectionID)
|
|
230
91
|
Remove the listener for a react component
|
|
231
92
|
|
|
232
|
-
**Kind**: global function
|
|
93
|
+
**Kind**: global function
|
|
233
94
|
|
|
234
|
-
| Param |
|
|
235
|
-
| --- | --- |
|
|
236
|
-
| connectionID |
|
|
237
|
-
| [keyToRemoveFromEvictionBlocklist] | <code>String</code> | |
|
|
95
|
+
| Param | Description |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| connectionID | unique id returned by call to Onyx.connect() |
|
|
238
98
|
|
|
239
|
-
**Example**
|
|
99
|
+
**Example**
|
|
240
100
|
```js
|
|
241
101
|
Onyx.disconnect(connectionID);
|
|
242
102
|
```
|
|
243
|
-
<a name="scheduleSubscriberUpdate"></a>
|
|
244
|
-
|
|
245
|
-
## scheduleSubscriberUpdate(key, value, prevValue, [canUpdateSubscriber]) ⇒ <code>Promise</code>
|
|
246
|
-
Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
|
|
247
|
-
|
|
248
|
-
**Kind**: global function
|
|
249
|
-
|
|
250
|
-
| Param | Type | Description |
|
|
251
|
-
| --- | --- | --- |
|
|
252
|
-
| key | <code>String</code> | |
|
|
253
|
-
| value | <code>\*</code> | |
|
|
254
|
-
| prevValue | <code>\*</code> | |
|
|
255
|
-
| [canUpdateSubscriber] | <code>function</code> | only subscribers that pass this truth test will be updated |
|
|
256
|
-
|
|
257
|
-
**Example**
|
|
258
|
-
```js
|
|
259
|
-
scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
|
|
260
|
-
```
|
|
261
|
-
<a name="scheduleNotifyCollectionSubscribers"></a>
|
|
262
|
-
|
|
263
|
-
## scheduleNotifyCollectionSubscribers(key, value) ⇒ <code>Promise</code>
|
|
264
|
-
This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections
|
|
265
|
-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
|
|
266
|
-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
|
|
267
|
-
|
|
268
|
-
**Kind**: global function
|
|
269
|
-
|
|
270
|
-
| Param | Type |
|
|
271
|
-
| --- | --- |
|
|
272
|
-
| key | <code>String</code> |
|
|
273
|
-
| value | <code>\*</code> |
|
|
274
|
-
|
|
275
|
-
<a name="broadcastUpdate"></a>
|
|
276
|
-
|
|
277
|
-
## broadcastUpdate(key, value, hasChanged, wasRemoved) ⇒ <code>Promise</code>
|
|
278
|
-
Notifys subscribers and writes current value to cache
|
|
279
|
-
|
|
280
|
-
**Kind**: global function
|
|
281
|
-
|
|
282
|
-
| Param | Type | Default |
|
|
283
|
-
| --- | --- | --- |
|
|
284
|
-
| key | <code>String</code> | |
|
|
285
|
-
| value | <code>\*</code> | |
|
|
286
|
-
| hasChanged | <code>Boolean</code> | |
|
|
287
|
-
| wasRemoved | <code>Boolean</code> | <code>false</code> |
|
|
288
|
-
|
|
289
|
-
<a name="hasPendingMergeForKey"></a>
|
|
290
|
-
|
|
291
|
-
## hasPendingMergeForKey(key) ⇒ <code>Boolean</code>
|
|
292
|
-
**Kind**: global function
|
|
293
|
-
|
|
294
|
-
| Param | Type |
|
|
295
|
-
| --- | --- |
|
|
296
|
-
| key | <code>String</code> |
|
|
297
|
-
|
|
298
|
-
<a name="removeNullValues"></a>
|
|
299
|
-
|
|
300
|
-
## removeNullValues(key, value) ⇒ <code>Mixed</code>
|
|
301
|
-
Removes a key from storage if the value is null.
|
|
302
|
-
Otherwise removes all nested null values in objects and returns the object
|
|
303
|
-
|
|
304
|
-
**Kind**: global function
|
|
305
|
-
**Returns**: <code>Mixed</code> - The value without null values and a boolean "wasRemoved", which indicates if the key got removed completely
|
|
306
|
-
|
|
307
|
-
| Param | Type |
|
|
308
|
-
| --- | --- |
|
|
309
|
-
| key | <code>String</code> |
|
|
310
|
-
| value | <code>Mixed</code> |
|
|
311
|
-
|
|
312
103
|
<a name="set"></a>
|
|
313
104
|
|
|
314
|
-
## set(key, value)
|
|
105
|
+
## set(key, value)
|
|
315
106
|
Write a value to our store with the given key
|
|
316
107
|
|
|
317
|
-
**Kind**: global function
|
|
108
|
+
**Kind**: global function
|
|
318
109
|
|
|
319
|
-
| Param |
|
|
320
|
-
| --- | --- |
|
|
321
|
-
| key |
|
|
322
|
-
| value |
|
|
110
|
+
| Param | Description |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| key | ONYXKEY to set |
|
|
113
|
+
| value | value to store |
|
|
323
114
|
|
|
324
115
|
<a name="multiSet"></a>
|
|
325
116
|
|
|
326
|
-
## multiSet(data)
|
|
117
|
+
## multiSet(data)
|
|
327
118
|
Sets multiple keys and values
|
|
328
119
|
|
|
329
|
-
**Kind**: global function
|
|
120
|
+
**Kind**: global function
|
|
330
121
|
|
|
331
|
-
| Param |
|
|
332
|
-
| --- | --- |
|
|
333
|
-
| data |
|
|
122
|
+
| Param | Description |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| data | object keyed by ONYXKEYS and the values to set |
|
|
334
125
|
|
|
335
|
-
**Example**
|
|
126
|
+
**Example**
|
|
336
127
|
```js
|
|
337
128
|
Onyx.multiSet({'key1': 'a', 'key2': 'b'});
|
|
338
129
|
```
|
|
339
130
|
<a name="merge"></a>
|
|
340
131
|
|
|
341
|
-
## merge(
|
|
132
|
+
## merge()
|
|
342
133
|
Merge a new value into an existing value at a key.
|
|
343
134
|
|
|
344
135
|
The types of values that can be merged are `Object` and `Array`. To set another type of value use `Onyx.set()`.
|
|
@@ -348,23 +139,36 @@ Calls to `Onyx.merge()` are batched so that any calls performed in a single tick
|
|
|
348
139
|
applied in the order they were called. Note: `Onyx.set()` calls do not work this way so use caution when mixing
|
|
349
140
|
`Onyx.merge()` and `Onyx.set()`.
|
|
350
141
|
|
|
351
|
-
**Kind**: global function
|
|
352
|
-
|
|
353
|
-
| Param | Type | Description |
|
|
354
|
-
| --- | --- | --- |
|
|
355
|
-
| key | <code>String</code> | ONYXKEYS key |
|
|
356
|
-
| changes | <code>Object</code> \| <code>Array</code> | Object or Array value to merge |
|
|
357
|
-
|
|
358
|
-
**Example**
|
|
142
|
+
**Kind**: global function
|
|
143
|
+
**Example**
|
|
359
144
|
```js
|
|
360
145
|
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
|
|
361
146
|
Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Joe', 'Jack']
|
|
362
147
|
Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
|
|
363
148
|
Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
|
|
364
149
|
```
|
|
150
|
+
<a name="mergeCollection"></a>
|
|
151
|
+
|
|
152
|
+
## mergeCollection(collectionKey, collection)
|
|
153
|
+
Merges a collection based on their keys
|
|
154
|
+
|
|
155
|
+
**Kind**: global function
|
|
156
|
+
|
|
157
|
+
| Param | Description |
|
|
158
|
+
| --- | --- |
|
|
159
|
+
| collectionKey | e.g. `ONYXKEYS.COLLECTION.REPORT` |
|
|
160
|
+
| collection | Object collection keyed by individual collection member keys and values |
|
|
161
|
+
|
|
162
|
+
**Example**
|
|
163
|
+
```js
|
|
164
|
+
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
165
|
+
[`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
|
|
166
|
+
[`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
167
|
+
});
|
|
168
|
+
```
|
|
365
169
|
<a name="clear"></a>
|
|
366
170
|
|
|
367
|
-
## clear(keysToPreserve)
|
|
171
|
+
## clear(keysToPreserve)
|
|
368
172
|
Clear out all the data in the store
|
|
369
173
|
|
|
370
174
|
Note that calling Onyx.clear() and then Onyx.set() on a key with a default
|
|
@@ -383,67 +187,21 @@ Onyx.get(key) before calling Storage.setItem() via Onyx.set().
|
|
|
383
187
|
Storage.setItem() from Onyx.clear() will have already finished and the merged
|
|
384
188
|
value will be saved to storage after the default value.
|
|
385
189
|
|
|
386
|
-
**Kind**: global function
|
|
190
|
+
**Kind**: global function
|
|
387
191
|
|
|
388
|
-
| Param |
|
|
389
|
-
| --- | --- |
|
|
390
|
-
| keysToPreserve |
|
|
391
|
-
|
|
392
|
-
<a name="mergeCollection"></a>
|
|
393
|
-
|
|
394
|
-
## mergeCollection(collectionKey, collection) ⇒ <code>Promise</code>
|
|
395
|
-
Merges a collection based on their keys
|
|
396
|
-
|
|
397
|
-
**Kind**: global function
|
|
398
|
-
|
|
399
|
-
| Param | Type | Description |
|
|
400
|
-
| --- | --- | --- |
|
|
401
|
-
| collectionKey | <code>String</code> | e.g. `ONYXKEYS.COLLECTION.REPORT` |
|
|
402
|
-
| collection | <code>Object</code> | Object collection keyed by individual collection member keys and values |
|
|
192
|
+
| Param | Description |
|
|
193
|
+
| --- | --- |
|
|
194
|
+
| keysToPreserve | is a list of ONYXKEYS that should not be cleared with the rest of the data |
|
|
403
195
|
|
|
404
|
-
**Example**
|
|
405
|
-
```js
|
|
406
|
-
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
407
|
-
[`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
|
|
408
|
-
[`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
409
|
-
});
|
|
410
|
-
```
|
|
411
196
|
<a name="update"></a>
|
|
412
197
|
|
|
413
|
-
## update(data) ⇒
|
|
198
|
+
## update(data) ⇒
|
|
414
199
|
Insert API responses and lifecycle data into Onyx
|
|
415
200
|
|
|
416
|
-
**Kind**: global function
|
|
417
|
-
**Returns**:
|
|
418
|
-
|
|
419
|
-
| Param | Type | Description |
|
|
420
|
-
| --- | --- | --- |
|
|
421
|
-
| data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *} |
|
|
422
|
-
|
|
423
|
-
<a name="init"></a>
|
|
424
|
-
|
|
425
|
-
## init([options])
|
|
426
|
-
Initialize the store with actions and listening for storage events
|
|
427
|
-
|
|
428
|
-
**Kind**: global function
|
|
201
|
+
**Kind**: global function
|
|
202
|
+
**Returns**: resolves when all operations are complete
|
|
429
203
|
|
|
430
|
-
| Param |
|
|
431
|
-
| --- | --- |
|
|
432
|
-
|
|
|
433
|
-
| [options.keys] | <code>Object</code> | <code>{}</code> | `ONYXKEYS` constants object |
|
|
434
|
-
| [options.initialKeyStates] | <code>Object</code> | <code>{}</code> | initial data to set when `init()` and `clear()` is called |
|
|
435
|
-
| [options.safeEvictionKeys] | <code>Array.<String></code> | <code>[]</code> | This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal. Any components subscribing to these keys must also implement a canEvict option. See the README for more info. |
|
|
436
|
-
| [options.maxCachedKeysCount] | <code>Number</code> | <code>55</code> | Sets how many recent keys should we try to keep in cache Setting this to 0 would practically mean no cache We try to free cache when we connect to a safe eviction key |
|
|
437
|
-
| [options.captureMetrics] | <code>Boolean</code> | | Enables Onyx benchmarking and exposes the get/print/reset functions |
|
|
438
|
-
| [options.shouldSyncMultipleInstances] | <code>Boolean</code> | | Auto synchronize storage events between multiple instances of Onyx running in different tabs/windows. Defaults to true for platforms that support local storage (web/desktop) |
|
|
439
|
-
| [options.debugSetState] | <code>Boolean</code> | | Enables debugging setState() calls to connected components. |
|
|
204
|
+
| Param | Description |
|
|
205
|
+
| --- | --- |
|
|
206
|
+
| data | An array of objects with update expressions |
|
|
440
207
|
|
|
441
|
-
**Example**
|
|
442
|
-
```js
|
|
443
|
-
Onyx.init({
|
|
444
|
-
keys: ONYXKEYS,
|
|
445
|
-
initialKeyStates: {
|
|
446
|
-
[ONYXKEYS.SESSION]: {loading: false},
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
```
|
package/dist/DevTools.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare class DevTools {
|
|
|
30
30
|
* @param payload - data written to the storage
|
|
31
31
|
* @param stateChanges - partial state that got updated after the changes
|
|
32
32
|
*/
|
|
33
|
-
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown>): void;
|
|
33
|
+
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown> | null): void;
|
|
34
34
|
initState(initialState?: Record<string, unknown>): void;
|
|
35
35
|
/**
|
|
36
36
|
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
package/dist/Onyx.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare function init({ keys, initialKeyStates, safeEvictionKeys, maxCachedKeysC
|
|
|
30
30
|
* Note that it will not cause the component to have the loading prop set to true.
|
|
31
31
|
* @returns an ID to use when calling disconnect
|
|
32
32
|
*/
|
|
33
|
-
declare function connect<TKey extends OnyxKey>(
|
|
33
|
+
declare function connect<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKey>): number;
|
|
34
34
|
/**
|
|
35
35
|
* Remove the listener for a react component
|
|
36
36
|
* @example
|
|
@@ -45,7 +45,7 @@ declare function disconnect(connectionID: number, keyToRemoveFromEvictionBlockli
|
|
|
45
45
|
* @param key ONYXKEY to set
|
|
46
46
|
* @param value value to store
|
|
47
47
|
*/
|
|
48
|
-
declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxEntry<KeyValueMapping[TKey]>): Promise<void
|
|
48
|
+
declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxEntry<KeyValueMapping[TKey]>): Promise<void>;
|
|
49
49
|
/**
|
|
50
50
|
* Sets multiple keys and values
|
|
51
51
|
*
|
|
@@ -53,7 +53,7 @@ declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxEntry<KeyValueM
|
|
|
53
53
|
*
|
|
54
54
|
* @param data object keyed by ONYXKEYS and the values to set
|
|
55
55
|
*/
|
|
56
|
-
declare function multiSet(data: Partial<NullableKeyValueMapping>): Promise<void
|
|
56
|
+
declare function multiSet(data: Partial<NullableKeyValueMapping>): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* Merge a new value into an existing value at a key.
|
|
59
59
|
*
|
|
@@ -70,7 +70,7 @@ declare function multiSet(data: Partial<NullableKeyValueMapping>): Promise<void[
|
|
|
70
70
|
* Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
|
|
71
71
|
* Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
|
|
72
72
|
*/
|
|
73
|
-
declare function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxEntry<NullishDeep<KeyValueMapping[TKey]>>): Promise<void
|
|
73
|
+
declare function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxEntry<NullishDeep<KeyValueMapping[TKey]>>): Promise<void>;
|
|
74
74
|
/**
|
|
75
75
|
* Merges a collection based on their keys
|
|
76
76
|
*
|
|
@@ -106,14 +106,14 @@ declare function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectio
|
|
|
106
106
|
*
|
|
107
107
|
* @param keysToPreserve is a list of ONYXKEYS that should not be cleared with the rest of the data
|
|
108
108
|
*/
|
|
109
|
-
declare function clear(keysToPreserve?: OnyxKey[]): Promise<void
|
|
109
|
+
declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
|
|
110
110
|
/**
|
|
111
111
|
* Insert API responses and lifecycle data into Onyx
|
|
112
112
|
*
|
|
113
|
-
* @param data An array of objects with
|
|
113
|
+
* @param data An array of objects with update expressions
|
|
114
114
|
* @returns resolves when all operations are complete
|
|
115
115
|
*/
|
|
116
|
-
declare function update(data: OnyxUpdate[]): Promise<
|
|
116
|
+
declare function update(data: OnyxUpdate[]): Promise<void>;
|
|
117
117
|
declare const Onyx: {
|
|
118
118
|
readonly METHOD: {
|
|
119
119
|
readonly SET: "set";
|