react-native-onyx 1.0.79 → 1.0.80
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 +72 -17
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<dl>
|
|
8
8
|
<dt><a href="#getSubsetOfData">getSubsetOfData(sourceData, selector, [withOnyxInstanceState])</a> ⇒ <code>Mixed</code></dt>
|
|
9
|
-
<dd><p>Uses a selector
|
|
9
|
+
<dd><p>Uses a selector function to return a simplified version of sourceData</p>
|
|
10
10
|
</dd>
|
|
11
11
|
<dt><a href="#reduceCollectionWithSelector">reduceCollectionWithSelector(collection, selector, [withOnyxInstanceState])</a> ⇒ <code>Object</code></dt>
|
|
12
12
|
<dd><p>Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
|
|
@@ -15,6 +15,10 @@ The resulting collection will only contain items that are returned by the select
|
|
|
15
15
|
</dd>
|
|
16
16
|
<dt><a href="#isCollectionMemberKey">isCollectionMemberKey(collectionKey, key)</a> ⇒ <code>Boolean</code></dt>
|
|
17
17
|
<dd></dd>
|
|
18
|
+
<dt><a href="#tryGetCachedValue">tryGetCachedValue(key, mapping)</a> ⇒ <code>Mixed</code></dt>
|
|
19
|
+
<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.
|
|
20
|
+
If the requested key is a collection, it will return an object with all the collection members.</p>
|
|
21
|
+
</dd>
|
|
18
22
|
<dt><a href="#connect">connect(mapping)</a> ⇒ <code>Number</code></dt>
|
|
19
23
|
<dd><p>Subscribes a react component's state directly to a store key</p>
|
|
20
24
|
</dd>
|
|
@@ -32,18 +36,21 @@ behavior just yet.</p>
|
|
|
32
36
|
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
|
|
33
37
|
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.</p>
|
|
34
38
|
</dd>
|
|
39
|
+
<dt><a href="#broadcastUpdate">broadcastUpdate(key, value, hasChanged, method)</a></dt>
|
|
40
|
+
<dd><p>Notifys subscribers and writes current value to cache</p>
|
|
41
|
+
</dd>
|
|
42
|
+
<dt><a href="#hasPendingMergeForKey">hasPendingMergeForKey(key)</a> ⇒ <code>Boolean</code></dt>
|
|
43
|
+
<dd></dd>
|
|
35
44
|
<dt><a href="#set">set(key, value)</a> ⇒ <code>Promise</code></dt>
|
|
36
45
|
<dd><p>Write a value to our store with the given key</p>
|
|
37
46
|
</dd>
|
|
38
47
|
<dt><a href="#multiSet">multiSet(data)</a> ⇒ <code>Promise</code></dt>
|
|
39
48
|
<dd><p>Sets multiple keys and values</p>
|
|
40
49
|
</dd>
|
|
41
|
-
<dt><a href="#merge">merge(key,
|
|
50
|
+
<dt><a href="#merge">merge(key, changes)</a> ⇒ <code>Promise</code></dt>
|
|
42
51
|
<dd><p>Merge a new value into an existing value at a key.</p>
|
|
43
|
-
<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>.
|
|
44
|
-
|
|
45
|
-
to note that if you have an array value property on an <code>Object</code> that the default behavior of lodash/merge is not to
|
|
46
|
-
concatenate. See here: <a href="https://github.com/lodash/lodash/issues/2872">https://github.com/lodash/lodash/issues/2872</a></p>
|
|
52
|
+
<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>.
|
|
53
|
+
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>
|
|
47
54
|
<p>Calls to <code>Onyx.merge()</code> are batched so that any calls performed in a single tick will stack in a queue and get
|
|
48
55
|
applied in the order they were called. Note: <code>Onyx.set()</code> calls do not work this way so use caution when mixing
|
|
49
56
|
<code>Onyx.merge()</code> and <code>Onyx.set()</code>.</p>
|
|
@@ -70,6 +77,9 @@ value will be saved to storage after the default value.</p>
|
|
|
70
77
|
<dt><a href="#update">update(data)</a> ⇒ <code>Promise</code></dt>
|
|
71
78
|
<dd><p>Insert API responses and lifecycle data into Onyx</p>
|
|
72
79
|
</dd>
|
|
80
|
+
<dt><a href="#setMemoryOnlyKeys">setMemoryOnlyKeys(keyList)</a></dt>
|
|
81
|
+
<dd><p>When set these keys will not be persisted to storage</p>
|
|
82
|
+
</dd>
|
|
73
83
|
<dt><a href="#init">init([options])</a></dt>
|
|
74
84
|
<dd><p>Initialize the store with actions and listening for storage events</p>
|
|
75
85
|
</dd>
|
|
@@ -78,15 +88,15 @@ value will be saved to storage after the default value.</p>
|
|
|
78
88
|
<a name="getSubsetOfData"></a>
|
|
79
89
|
|
|
80
90
|
## getSubsetOfData(sourceData, selector, [withOnyxInstanceState]) ⇒ <code>Mixed</code>
|
|
81
|
-
Uses a selector
|
|
91
|
+
Uses a selector function to return a simplified version of sourceData
|
|
82
92
|
|
|
83
93
|
**Kind**: global function
|
|
84
94
|
|
|
85
95
|
| Param | Type | Description |
|
|
86
96
|
| --- | --- | --- |
|
|
87
97
|
| sourceData | <code>Mixed</code> | |
|
|
88
|
-
| selector | <code>
|
|
89
|
-
| [withOnyxInstanceState] | <code>Object</code> |
|
|
98
|
+
| selector | <code>function</code> | Function that takes sourceData and returns a simplified version of it |
|
|
99
|
+
| [withOnyxInstanceState] | <code>Object</code> | |
|
|
90
100
|
|
|
91
101
|
<a name="reduceCollectionWithSelector"></a>
|
|
92
102
|
|
|
@@ -113,6 +123,19 @@ The resulting collection will only contain items that are returned by the select
|
|
|
113
123
|
| collectionKey | <code>String</code> |
|
|
114
124
|
| key | <code>String</code> |
|
|
115
125
|
|
|
126
|
+
<a name="tryGetCachedValue"></a>
|
|
127
|
+
|
|
128
|
+
## tryGetCachedValue(key, mapping) ⇒ <code>Mixed</code>
|
|
129
|
+
Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
130
|
+
If the requested key is a collection, it will return an object with all the collection members.
|
|
131
|
+
|
|
132
|
+
**Kind**: global function
|
|
133
|
+
|
|
134
|
+
| Param | Type |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| key | <code>String</code> |
|
|
137
|
+
| mapping | <code>Object</code> |
|
|
138
|
+
|
|
116
139
|
<a name="connect"></a>
|
|
117
140
|
|
|
118
141
|
## connect(mapping) ⇒ <code>Number</code>
|
|
@@ -130,7 +153,7 @@ Subscribes a react component's state directly to a store key
|
|
|
130
153
|
| [mapping.callback] | <code>function</code> | a method that will be called with changed data This is used by any non-React code to connect to Onyx |
|
|
131
154
|
| [mapping.initWithStoredValues] | <code>Boolean</code> | If set to false, then no data will be prefilled into the component |
|
|
132
155
|
| [mapping.waitForCollectionCallback] | <code>Boolean</code> | If set to true, it will return the entire collection to the callback as a single object |
|
|
133
|
-
| [mapping.selector] | <code>
|
|
156
|
+
| [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). |
|
|
134
157
|
|
|
135
158
|
**Example**
|
|
136
159
|
```js
|
|
@@ -189,6 +212,29 @@ subscriber callbacks receive the data in a different format than they normally e
|
|
|
189
212
|
| key | <code>String</code> |
|
|
190
213
|
| value | <code>\*</code> |
|
|
191
214
|
|
|
215
|
+
<a name="broadcastUpdate"></a>
|
|
216
|
+
|
|
217
|
+
## broadcastUpdate(key, value, hasChanged, method)
|
|
218
|
+
Notifys subscribers and writes current value to cache
|
|
219
|
+
|
|
220
|
+
**Kind**: global function
|
|
221
|
+
|
|
222
|
+
| Param | Type |
|
|
223
|
+
| --- | --- |
|
|
224
|
+
| key | <code>String</code> |
|
|
225
|
+
| value | <code>\*</code> |
|
|
226
|
+
| hasChanged | <code>Boolean</code> |
|
|
227
|
+
| method | <code>String</code> |
|
|
228
|
+
|
|
229
|
+
<a name="hasPendingMergeForKey"></a>
|
|
230
|
+
|
|
231
|
+
## hasPendingMergeForKey(key) ⇒ <code>Boolean</code>
|
|
232
|
+
**Kind**: global function
|
|
233
|
+
|
|
234
|
+
| Param | Type |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| key | <code>String</code> |
|
|
237
|
+
|
|
192
238
|
<a name="set"></a>
|
|
193
239
|
|
|
194
240
|
## set(key, value) ⇒ <code>Promise</code>
|
|
@@ -218,13 +264,11 @@ Onyx.multiSet({'key1': 'a', 'key2': 'b'});
|
|
|
218
264
|
```
|
|
219
265
|
<a name="merge"></a>
|
|
220
266
|
|
|
221
|
-
## merge(key,
|
|
267
|
+
## merge(key, changes) ⇒ <code>Promise</code>
|
|
222
268
|
Merge a new value into an existing value at a key.
|
|
223
269
|
|
|
224
|
-
The types of values that can be merged are `Object` and `Array`. To set another type of value use `Onyx.set()`.
|
|
225
|
-
|
|
226
|
-
to note that if you have an array value property on an `Object` that the default behavior of lodash/merge is not to
|
|
227
|
-
concatenate. See here: https://github.com/lodash/lodash/issues/2872
|
|
270
|
+
The types of values that can be merged are `Object` and `Array`. To set another type of value use `Onyx.set()`.
|
|
271
|
+
Values of type `Object` get merged with the old value, whilst for `Array`'s we simply replace the current value with the new one.
|
|
228
272
|
|
|
229
273
|
Calls to `Onyx.merge()` are batched so that any calls performed in a single tick will stack in a queue and get
|
|
230
274
|
applied in the order they were called. Note: `Onyx.set()` calls do not work this way so use caution when mixing
|
|
@@ -235,7 +279,7 @@ applied in the order they were called. Note: `Onyx.set()` calls do not work this
|
|
|
235
279
|
| Param | Type | Description |
|
|
236
280
|
| --- | --- | --- |
|
|
237
281
|
| key | <code>String</code> | ONYXKEYS key |
|
|
238
|
-
|
|
|
282
|
+
| changes | <code>Object</code> \| <code>Array</code> | Object or Array value to merge |
|
|
239
283
|
|
|
240
284
|
**Example**
|
|
241
285
|
```js
|
|
@@ -300,7 +344,18 @@ Insert API responses and lifecycle data into Onyx
|
|
|
300
344
|
|
|
301
345
|
| Param | Type | Description |
|
|
302
346
|
| --- | --- | --- |
|
|
303
|
-
| data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *} |
|
|
347
|
+
| data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *} |
|
|
348
|
+
|
|
349
|
+
<a name="setMemoryOnlyKeys"></a>
|
|
350
|
+
|
|
351
|
+
## setMemoryOnlyKeys(keyList)
|
|
352
|
+
When set these keys will not be persisted to storage
|
|
353
|
+
|
|
354
|
+
**Kind**: global function
|
|
355
|
+
|
|
356
|
+
| Param | Type |
|
|
357
|
+
| --- | --- |
|
|
358
|
+
| keyList | <code>Array.<string></code> |
|
|
304
359
|
|
|
305
360
|
<a name="init"></a>
|
|
306
361
|
|