react-native-onyx 2.0.21 → 2.0.23

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.
Files changed (41) hide show
  1. package/API.md +49 -64
  2. package/dist/DevTools.js +0 -1
  3. package/dist/Onyx.d.ts +49 -258
  4. package/dist/Onyx.js +192 -1165
  5. package/dist/OnyxCache.d.ts +14 -15
  6. package/dist/OnyxUtils.d.ts +320 -0
  7. package/dist/OnyxUtils.js +1061 -0
  8. package/dist/PerformanceUtils.d.ts +3 -5
  9. package/dist/index.d.ts +3 -2
  10. package/dist/storage/InstanceSync/index.d.ts +14 -0
  11. package/dist/storage/InstanceSync/index.js +20 -0
  12. package/dist/storage/InstanceSync/index.web.d.ts +27 -0
  13. package/dist/storage/InstanceSync/index.web.js +59 -0
  14. package/dist/storage/__mocks__/index.d.ts +15 -13
  15. package/dist/storage/__mocks__/index.js +43 -81
  16. package/dist/storage/index.d.ts +6 -2
  17. package/dist/storage/index.js +170 -2
  18. package/dist/storage/platforms/index.d.ts +2 -0
  19. package/dist/storage/{NativeStorage.js → platforms/index.js} +2 -2
  20. package/dist/storage/platforms/index.native.d.ts +2 -0
  21. package/dist/storage/{index.native.js → platforms/index.native.js} +2 -2
  22. package/dist/storage/providers/{IDBKeyVal.js → IDBKeyValProvider.js} +23 -19
  23. package/dist/storage/providers/MemoryOnlyProvider.d.ts +9 -0
  24. package/dist/storage/providers/MemoryOnlyProvider.js +124 -0
  25. package/dist/storage/providers/NoopProvider.js +85 -0
  26. package/dist/storage/providers/SQLiteProvider.d.ts +3 -0
  27. package/dist/storage/providers/{SQLiteStorage.js → SQLiteProvider.js} +17 -11
  28. package/dist/storage/providers/types.d.ts +17 -14
  29. package/dist/types.d.ts +128 -55
  30. package/dist/types.js +2 -0
  31. package/dist/useOnyx.js +11 -10
  32. package/dist/utils.d.ts +2 -2
  33. package/dist/utils.js +29 -16
  34. package/dist/withOnyx.js +6 -5
  35. package/package.json +1 -1
  36. package/dist/storage/NativeStorage.d.ts +0 -2
  37. package/dist/storage/WebStorage.d.ts +0 -3
  38. package/dist/storage/WebStorage.js +0 -62
  39. package/dist/storage/index.native.d.ts +0 -2
  40. /package/dist/storage/providers/{IDBKeyVal.d.ts → IDBKeyValProvider.d.ts} +0 -0
  41. /package/dist/storage/providers/{SQLiteStorage.d.ts → NoopProvider.d.ts} +0 -0
package/API.md CHANGED
@@ -49,7 +49,7 @@ If the requested key is a collection, it will return an object with all the coll
49
49
  so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
50
50
  subscriber callbacks receive the data in a different format than they normally expect and it breaks code.</p>
51
51
  </dd>
52
- <dt><a href="#broadcastUpdate">broadcastUpdate(key, value, method, hasChanged, wasRemoved)</a> ⇒ <code>Promise</code></dt>
52
+ <dt><a href="#broadcastUpdate">broadcastUpdate(key, value, hasChanged, wasRemoved)</a> ⇒ <code>Promise</code></dt>
53
53
  <dd><p>Notifys subscribers and writes current value to cache</p>
54
54
  </dd>
55
55
  <dt><a href="#hasPendingMergeForKey">hasPendingMergeForKey(key)</a> ⇒ <code>Boolean</code></dt>
@@ -94,9 +94,6 @@ value will be saved to storage after the default value.</p>
94
94
  <dt><a href="#update">update(data)</a> ⇒ <code>Promise</code></dt>
95
95
  <dd><p>Insert API responses and lifecycle data into Onyx</p>
96
96
  </dd>
97
- <dt><a href="#setMemoryOnlyKeys">setMemoryOnlyKeys(keyList)</a></dt>
98
- <dd><p>When set these keys will not be persisted to storage</p>
99
- </dd>
100
97
  <dt><a href="#init">init([options])</a></dt>
101
98
  <dd><p>Initialize the store with actions and listening for storage events</p>
102
99
  </dd>
@@ -107,7 +104,7 @@ value will be saved to storage after the default value.</p>
107
104
  ## sendActionToDevTools(method, key, value, mergedValue)
108
105
  Sends an action to DevTools extension
109
106
 
110
- **Kind**: global function
107
+ **Kind**: global function
111
108
 
112
109
  | Param | Type | Description |
113
110
  | --- | --- | --- |
@@ -124,13 +121,13 @@ This happens for example in the Onyx.update function, where we process API respo
124
121
  update operations. Instead of calling the subscribers for each update operation, we batch them together which will
125
122
  cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization.
126
123
 
127
- **Kind**: global function
124
+ **Kind**: global function
128
125
  <a name="getSubsetOfData"></a>
129
126
 
130
127
  ## getSubsetOfData(sourceData, selector, [withOnyxInstanceState]) ⇒ <code>Mixed</code>
131
128
  Uses a selector function to return a simplified version of sourceData
132
129
 
133
- **Kind**: global function
130
+ **Kind**: global function
134
131
 
135
132
  | Param | Type | Description |
136
133
  | --- | --- | --- |
@@ -145,7 +142,7 @@ Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
145
142
  and runs it through a reducer function to return a subset of the data according to a selector.
146
143
  The resulting collection will only contain items that are returned by the selector.
147
144
 
148
- **Kind**: global function
145
+ **Kind**: global function
149
146
 
150
147
  | Param | Type | Description |
151
148
  | --- | --- | --- |
@@ -159,29 +156,29 @@ The resulting collection will only contain items that are returned by the select
159
156
  Checks to see if the a subscriber's supplied key
160
157
  is associated with a collection of keys.
161
158
 
162
- **Kind**: global function
159
+ **Kind**: global function
163
160
 
164
161
  | Param | Type |
165
162
  | --- | --- |
166
- | key | <code>String</code> |
163
+ | key | <code>String</code> |
167
164
 
168
165
  <a name="isCollectionMemberKey"></a>
169
166
 
170
167
  ## isCollectionMemberKey(collectionKey, key) ⇒ <code>Boolean</code>
171
- **Kind**: global function
168
+ **Kind**: global function
172
169
 
173
170
  | Param | Type |
174
171
  | --- | --- |
175
- | collectionKey | <code>String</code> |
176
- | key | <code>String</code> |
172
+ | collectionKey | <code>String</code> |
173
+ | key | <code>String</code> |
177
174
 
178
175
  <a name="splitCollectionMemberKey"></a>
179
176
 
180
177
  ## splitCollectionMemberKey(key) ⇒ <code>Array.&lt;String&gt;</code>
181
178
  Splits a collection member key into the collection key part and the ID part.
182
179
 
183
- **Kind**: global function
184
- **Returns**: <code>Array.&lt;String&gt;</code> - A tuple where the first element is the collection part and the second element is the ID part.
180
+ **Kind**: global function
181
+ **Returns**: <code>Array.&lt;String&gt;</code> - A tuple where the first element is the collection part and the second element is the ID part.
185
182
 
186
183
  | Param | Type | Description |
187
184
  | --- | --- | --- |
@@ -193,20 +190,20 @@ Splits a collection member key into the collection key part and the ID part.
193
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.
194
191
  If the requested key is a collection, it will return an object with all the collection members.
195
192
 
196
- **Kind**: global function
193
+ **Kind**: global function
197
194
 
198
195
  | Param | Type |
199
196
  | --- | --- |
200
- | key | <code>String</code> |
201
- | mapping | <code>Object</code> |
197
+ | key | <code>String</code> |
198
+ | mapping | <code>Object</code> |
202
199
 
203
200
  <a name="connect"></a>
204
201
 
205
202
  ## connect(mapping) ⇒ <code>Number</code>
206
203
  Subscribes a react component's state directly to a store key
207
204
 
208
- **Kind**: global function
209
- **Returns**: <code>Number</code> - an ID to use when calling disconnect
205
+ **Kind**: global function
206
+ **Returns**: <code>Number</code> - an ID to use when calling disconnect
210
207
 
211
208
  | Param | Type | Description |
212
209
  | --- | --- | --- |
@@ -220,7 +217,7 @@ Subscribes a react component's state directly to a store key
220
217
  | [mapping.selector] | <code>function</code> | 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). |
221
218
  | [mapping.initialValue] | <code>String</code> \| <code>Number</code> \| <code>Boolean</code> \| <code>Object</code> | 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. | |
222
219
 
223
- **Example**
220
+ **Example**
224
221
  ```js
225
222
  const connectionID = Onyx.connect({
226
223
  key: ONYXKEYS.SESSION,
@@ -232,14 +229,14 @@ const connectionID = Onyx.connect({
232
229
  ## disconnect(connectionID, [keyToRemoveFromEvictionBlocklist])
233
230
  Remove the listener for a react component
234
231
 
235
- **Kind**: global function
232
+ **Kind**: global function
236
233
 
237
234
  | Param | Type | Description |
238
235
  | --- | --- | --- |
239
236
  | connectionID | <code>Number</code> | unique id returned by call to Onyx.connect() |
240
237
  | [keyToRemoveFromEvictionBlocklist] | <code>String</code> | |
241
238
 
242
- **Example**
239
+ **Example**
243
240
  ```js
244
241
  Onyx.disconnect(connectionID);
245
242
  ```
@@ -248,7 +245,7 @@ Onyx.disconnect(connectionID);
248
245
  ## scheduleSubscriberUpdate(key, value, prevValue, [canUpdateSubscriber]) ⇒ <code>Promise</code>
249
246
  Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
250
247
 
251
- **Kind**: global function
248
+ **Kind**: global function
252
249
 
253
250
  | Param | Type | Description |
254
251
  | --- | --- | --- |
@@ -257,7 +254,7 @@ Schedules an update that will be appended to the macro task queue (so it doesn't
257
254
  | prevValue | <code>\*</code> | |
258
255
  | [canUpdateSubscriber] | <code>function</code> | only subscribers that pass this truth test will be updated |
259
256
 
260
- **Example**
257
+ **Example**
261
258
  ```js
262
259
  scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
263
260
  ```
@@ -268,36 +265,35 @@ This method is similar to notifySubscribersOnNextTick but it is built for workin
268
265
  so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
269
266
  subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
270
267
 
271
- **Kind**: global function
268
+ **Kind**: global function
272
269
 
273
270
  | Param | Type |
274
271
  | --- | --- |
275
- | key | <code>String</code> |
276
- | value | <code>\*</code> |
272
+ | key | <code>String</code> |
273
+ | value | <code>\*</code> |
277
274
 
278
275
  <a name="broadcastUpdate"></a>
279
276
 
280
- ## broadcastUpdate(key, value, method, hasChanged, wasRemoved) ⇒ <code>Promise</code>
277
+ ## broadcastUpdate(key, value, hasChanged, wasRemoved) ⇒ <code>Promise</code>
281
278
  Notifys subscribers and writes current value to cache
282
279
 
283
- **Kind**: global function
280
+ **Kind**: global function
284
281
 
285
282
  | Param | Type | Default |
286
283
  | --- | --- | --- |
287
- | key | <code>String</code> | |
288
- | value | <code>\*</code> | |
289
- | method | <code>String</code> | |
290
- | hasChanged | <code>Boolean</code> | |
291
- | wasRemoved | <code>Boolean</code> | <code>false</code> |
284
+ | key | <code>String</code> | |
285
+ | value | <code>\*</code> | |
286
+ | hasChanged | <code>Boolean</code> | |
287
+ | wasRemoved | <code>Boolean</code> | <code>false</code> |
292
288
 
293
289
  <a name="hasPendingMergeForKey"></a>
294
290
 
295
291
  ## hasPendingMergeForKey(key) ⇒ <code>Boolean</code>
296
- **Kind**: global function
292
+ **Kind**: global function
297
293
 
298
294
  | Param | Type |
299
295
  | --- | --- |
300
- | key | <code>String</code> |
296
+ | key | <code>String</code> |
301
297
 
302
298
  <a name="removeNullValues"></a>
303
299
 
@@ -305,20 +301,20 @@ Notifys subscribers and writes current value to cache
305
301
  Removes a key from storage if the value is null.
306
302
  Otherwise removes all nested null values in objects and returns the object
307
303
 
308
- **Kind**: global function
309
- **Returns**: <code>Mixed</code> - The value without null values and a boolean "wasRemoved", which indicates if the key got removed completely
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
310
306
 
311
307
  | Param | Type |
312
308
  | --- | --- |
313
- | key | <code>String</code> |
314
- | value | <code>Mixed</code> |
309
+ | key | <code>String</code> |
310
+ | value | <code>Mixed</code> |
315
311
 
316
312
  <a name="set"></a>
317
313
 
318
314
  ## set(key, value) ⇒ <code>Promise</code>
319
315
  Write a value to our store with the given key
320
316
 
321
- **Kind**: global function
317
+ **Kind**: global function
322
318
 
323
319
  | Param | Type | Description |
324
320
  | --- | --- | --- |
@@ -330,13 +326,13 @@ Write a value to our store with the given key
330
326
  ## multiSet(data) ⇒ <code>Promise</code>
331
327
  Sets multiple keys and values
332
328
 
333
- **Kind**: global function
329
+ **Kind**: global function
334
330
 
335
331
  | Param | Type | Description |
336
332
  | --- | --- | --- |
337
333
  | data | <code>Object</code> | object keyed by ONYXKEYS and the values to set |
338
334
 
339
- **Example**
335
+ **Example**
340
336
  ```js
341
337
  Onyx.multiSet({'key1': 'a', 'key2': 'b'});
342
338
  ```
@@ -352,14 +348,14 @@ Calls to `Onyx.merge()` are batched so that any calls performed in a single tick
352
348
  applied in the order they were called. Note: `Onyx.set()` calls do not work this way so use caution when mixing
353
349
  `Onyx.merge()` and `Onyx.set()`.
354
350
 
355
- **Kind**: global function
351
+ **Kind**: global function
356
352
 
357
353
  | Param | Type | Description |
358
354
  | --- | --- | --- |
359
355
  | key | <code>String</code> | ONYXKEYS key |
360
356
  | changes | <code>Object</code> \| <code>Array</code> | Object or Array value to merge |
361
357
 
362
- **Example**
358
+ **Example**
363
359
  ```js
364
360
  Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
365
361
  Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Joe', 'Jack']
@@ -387,7 +383,7 @@ Onyx.get(key) before calling Storage.setItem() via Onyx.set().
387
383
  Storage.setItem() from Onyx.clear() will have already finished and the merged
388
384
  value will be saved to storage after the default value.
389
385
 
390
- **Kind**: global function
386
+ **Kind**: global function
391
387
 
392
388
  | Param | Type | Description |
393
389
  | --- | --- | --- |
@@ -398,14 +394,14 @@ value will be saved to storage after the default value.
398
394
  ## mergeCollection(collectionKey, collection) ⇒ <code>Promise</code>
399
395
  Merges a collection based on their keys
400
396
 
401
- **Kind**: global function
397
+ **Kind**: global function
402
398
 
403
399
  | Param | Type | Description |
404
400
  | --- | --- | --- |
405
401
  | collectionKey | <code>String</code> | e.g. `ONYXKEYS.COLLECTION.REPORT` |
406
402
  | collection | <code>Object</code> | Object collection keyed by individual collection member keys and values |
407
403
 
408
- **Example**
404
+ **Example**
409
405
  ```js
410
406
  Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
411
407
  [`${ONYXKEYS.COLLECTION.REPORT}1`]: report1,
@@ -417,30 +413,19 @@ Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
417
413
  ## update(data) ⇒ <code>Promise</code>
418
414
  Insert API responses and lifecycle data into Onyx
419
415
 
420
- **Kind**: global function
421
- **Returns**: <code>Promise</code> - resolves when all operations are complete
416
+ **Kind**: global function
417
+ **Returns**: <code>Promise</code> - resolves when all operations are complete
422
418
 
423
419
  | Param | Type | Description |
424
420
  | --- | --- | --- |
425
421
  | data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *} |
426
422
 
427
- <a name="setMemoryOnlyKeys"></a>
428
-
429
- ## setMemoryOnlyKeys(keyList)
430
- When set these keys will not be persisted to storage
431
-
432
- **Kind**: global function
433
-
434
- | Param | Type |
435
- | --- | --- |
436
- | keyList | <code>Array.&lt;string&gt;</code> |
437
-
438
423
  <a name="init"></a>
439
424
 
440
425
  ## init([options])
441
426
  Initialize the store with actions and listening for storage events
442
427
 
443
- **Kind**: global function
428
+ **Kind**: global function
444
429
 
445
430
  | Param | Type | Default | Description |
446
431
  | --- | --- | --- | --- |
@@ -453,7 +438,7 @@ Initialize the store with actions and listening for storage events
453
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) |
454
439
  | [options.debugSetState] | <code>Boolean</code> | | Enables debugging setState() calls to connected components. |
455
440
 
456
- **Example**
441
+ **Example**
457
442
  ```js
458
443
  Onyx.init({
459
444
  keys: ONYXKEYS,
package/dist/DevTools.js CHANGED
@@ -15,7 +15,6 @@ class DevTools {
15
15
  if ((options && options.remote) || typeof window === 'undefined' || !reduxDevtools) {
16
16
  return;
17
17
  }
18
- // eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
19
18
  return reduxDevtools.connect(options);
20
19
  }
21
20
  catch (e) {