react-native-onyx 1.0.79 → 1.0.81
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/dist/web.development.js +55 -29
- package/dist/web.development.js.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/lib/Onyx.js +4 -21
- package/lib/fastMerge.js +3 -4
- package/lib/storage/providers/IDBKeyVal.js +2 -1
- package/lib/utils.js +23 -0
- 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
|
|
package/dist/web.development.js
CHANGED
|
@@ -77,9 +77,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
77
77
|
/* harmony import */ var _OnyxCache__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./OnyxCache */ "./lib/OnyxCache.js");
|
|
78
78
|
/* harmony import */ var _Str__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Str */ "./lib/Str.js");
|
|
79
79
|
/* harmony import */ var _createDeferredTask__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js");
|
|
80
|
-
/* harmony import */ var
|
|
80
|
+
/* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./fastMerge */ "./lib/fastMerge.js");
|
|
81
81
|
/* harmony import */ var _metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./metrics/PerformanceUtils */ "./lib/metrics/PerformanceUtils.js");
|
|
82
82
|
/* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./storage */ "./lib/storage/index.web.js");
|
|
83
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
|
83
84
|
/* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./batch */ "./lib/batch.js");
|
|
84
85
|
/* eslint-disable no-continue */
|
|
85
86
|
|
|
@@ -93,6 +94,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
93
94
|
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
|
|
96
98
|
// Method constants
|
|
97
99
|
const METHOD = {
|
|
98
100
|
SET: 'set',
|
|
@@ -1073,24 +1075,6 @@ function hasPendingMergeForKey(key) {
|
|
|
1073
1075
|
return Boolean(mergeQueue[key]);
|
|
1074
1076
|
}
|
|
1075
1077
|
|
|
1076
|
-
/**
|
|
1077
|
-
* We generally want to remove top-level nullish values from objects written to disk and cache, because it decreases the amount of data stored in memory and on disk.
|
|
1078
|
-
* On native, when merging an existing value with new changes, SQLite will use JSON_PATCH, which removes top-level nullish values.
|
|
1079
|
-
* To be consistent with the behaviour for merge, we'll also want to remove nullish values for "set" operations.
|
|
1080
|
-
* On web, IndexedDB will keep the top-level keys along with a null value and this uses up storage and memory.
|
|
1081
|
-
* This method will ensure that keys for null values are removed before an object is written to disk and cache so that all platforms are storing the data in the same efficient way.
|
|
1082
|
-
* @private
|
|
1083
|
-
* @param {*} value
|
|
1084
|
-
* @returns {*}
|
|
1085
|
-
*/
|
|
1086
|
-
function removeNullObjectValues(value) {
|
|
1087
|
-
if (underscore__WEBPACK_IMPORTED_MODULE_1___default().isArray(value) || !underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(value)) {
|
|
1088
|
-
return value;
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
return underscore__WEBPACK_IMPORTED_MODULE_1___default().omit(value, (objectValue) => underscore__WEBPACK_IMPORTED_MODULE_1___default().isNull(objectValue));
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
1078
|
/**
|
|
1095
1079
|
* Write a value to our store with the given key
|
|
1096
1080
|
*
|
|
@@ -1108,7 +1092,7 @@ function set(key, value) {
|
|
|
1108
1092
|
_Logger__WEBPACK_IMPORTED_MODULE_5__.logAlert(`Onyx.set() called after Onyx.merge() for key: ${key}. It is recommended to use set() or merge() not both.`);
|
|
1109
1093
|
}
|
|
1110
1094
|
|
|
1111
|
-
const valueWithNullRemoved = removeNullObjectValues(value);
|
|
1095
|
+
const valueWithNullRemoved = _utils__WEBPACK_IMPORTED_MODULE_9__["default"].removeNullObjectValues(value);
|
|
1112
1096
|
|
|
1113
1097
|
const hasChanged = _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].hasValueChanged(key, valueWithNullRemoved);
|
|
1114
1098
|
|
|
@@ -1178,7 +1162,7 @@ function applyMerge(existingValue, changes) {
|
|
|
1178
1162
|
// Object values are merged one after the other
|
|
1179
1163
|
// lodash adds a small overhead so we don't use it here
|
|
1180
1164
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
1181
|
-
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) => (0,
|
|
1165
|
+
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) => (0,_fastMerge__WEBPACK_IMPORTED_MODULE_10__["default"])(modifiedData, change),
|
|
1182
1166
|
existingValue || {});
|
|
1183
1167
|
}
|
|
1184
1168
|
|
|
@@ -1227,14 +1211,14 @@ function merge(key, changes) {
|
|
|
1227
1211
|
delete mergeQueuePromise[key];
|
|
1228
1212
|
|
|
1229
1213
|
// After that we merge the batched changes with the existing value
|
|
1230
|
-
const modifiedData = removeNullObjectValues(applyMerge(existingValue, [batchedChanges]));
|
|
1214
|
+
const modifiedData = _utils__WEBPACK_IMPORTED_MODULE_9__["default"].removeNullObjectValues(applyMerge(existingValue, [batchedChanges]));
|
|
1231
1215
|
|
|
1232
1216
|
// On native platforms we use SQLite which utilises JSON_PATCH to merge changes.
|
|
1233
1217
|
// JSON_PATCH generally removes top-level nullish values from the stored object.
|
|
1234
1218
|
// When there is no existing value though, SQLite will just insert the changes as a new value and thus the top-level nullish values won't be removed.
|
|
1235
1219
|
// Therefore we need to remove nullish values from the `batchedChanges` which are sent to the SQLite, if no existing value is present.
|
|
1236
1220
|
if (!existingValue) {
|
|
1237
|
-
batchedChanges = removeNullObjectValues(batchedChanges);
|
|
1221
|
+
batchedChanges = _utils__WEBPACK_IMPORTED_MODULE_9__["default"].removeNullObjectValues(batchedChanges);
|
|
1238
1222
|
}
|
|
1239
1223
|
|
|
1240
1224
|
const hasChanged = _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].hasValueChanged(key, modifiedData);
|
|
@@ -1268,7 +1252,7 @@ function initializeWithDefaultKeyStates() {
|
|
|
1268
1252
|
then((pairs) => {
|
|
1269
1253
|
const asObject = underscore__WEBPACK_IMPORTED_MODULE_1___default().object(pairs);
|
|
1270
1254
|
|
|
1271
|
-
const merged = (0,
|
|
1255
|
+
const merged = (0,_fastMerge__WEBPACK_IMPORTED_MODULE_10__["default"])(asObject, defaultKeyStates);
|
|
1272
1256
|
_OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].merge(merged);
|
|
1273
1257
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(merged, (val, key) => keyChanged(key, val));
|
|
1274
1258
|
});
|
|
@@ -1977,6 +1961,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1977
1961
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1978
1962
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1979
1963
|
/* harmony export */ });
|
|
1964
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "underscore");
|
|
1965
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
|
|
1966
|
+
|
|
1967
|
+
|
|
1980
1968
|
// Mostly copied from https://medium.com/@lubaka.a/how-to-remove-lodash-performance-improvement-b306669ad0e1
|
|
1981
1969
|
|
|
1982
1970
|
/**
|
|
@@ -2033,10 +2021,7 @@ function mergeObject(target, source) {
|
|
|
2033
2021
|
* @returns {Object|Array}
|
|
2034
2022
|
*/
|
|
2035
2023
|
function fastMerge(target, source) {
|
|
2036
|
-
|
|
2037
|
-
// eslint-disable-next-line rulesdir/prefer-underscore-method
|
|
2038
|
-
const array = Array.isArray(source);
|
|
2039
|
-
if (array) {
|
|
2024
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_0___default().isArray(source) || underscore__WEBPACK_IMPORTED_MODULE_0___default().isNull(source) || underscore__WEBPACK_IMPORTED_MODULE_0___default().isUndefined(source)) {
|
|
2040
2025
|
return source;
|
|
2041
2026
|
}
|
|
2042
2027
|
return mergeObject(target, source);
|
|
@@ -2282,6 +2267,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2282
2267
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "underscore");
|
|
2283
2268
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
|
|
2284
2269
|
/* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../fastMerge */ "./lib/fastMerge.js");
|
|
2270
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../utils */ "./lib/utils.js");
|
|
2271
|
+
|
|
2285
2272
|
|
|
2286
2273
|
|
|
2287
2274
|
|
|
@@ -2329,7 +2316,7 @@ const provider = {
|
|
|
2329
2316
|
const upsertMany = underscore__WEBPACK_IMPORTED_MODULE_1___default().map(pairs, (_ref2, index) => {let [key, value] = _ref2;
|
|
2330
2317
|
const prev = values[index];
|
|
2331
2318
|
const newValue = underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(prev) ? (0,_fastMerge__WEBPACK_IMPORTED_MODULE_2__["default"])(prev, value) : value;
|
|
2332
|
-
return (0,idb_keyval__WEBPACK_IMPORTED_MODULE_0__.promisifyRequest)(store.put(newValue, key));
|
|
2319
|
+
return (0,idb_keyval__WEBPACK_IMPORTED_MODULE_0__.promisifyRequest)(store.put(_utils__WEBPACK_IMPORTED_MODULE_3__["default"].removeNullObjectValues(newValue), key));
|
|
2333
2320
|
});
|
|
2334
2321
|
return Promise.all(upsertMany);
|
|
2335
2322
|
});
|
|
@@ -2414,6 +2401,45 @@ const provider = {
|
|
|
2414
2401
|
|
|
2415
2402
|
/***/ }),
|
|
2416
2403
|
|
|
2404
|
+
/***/ "./lib/utils.js":
|
|
2405
|
+
/*!**********************!*\
|
|
2406
|
+
!*** ./lib/utils.js ***!
|
|
2407
|
+
\**********************/
|
|
2408
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2409
|
+
|
|
2410
|
+
"use strict";
|
|
2411
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2412
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2413
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
2414
|
+
/* harmony export */ });
|
|
2415
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "underscore");
|
|
2416
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
/**
|
|
2420
|
+
* We generally want to remove top-level nullish values from objects written to disk and cache, because it decreases the amount of data stored in memory and on disk.
|
|
2421
|
+
* On native, when merging an existing value with new changes, SQLite will use JSON_PATCH, which removes top-level nullish values.
|
|
2422
|
+
* To be consistent with the behaviour for merge, we'll also want to remove nullish values for "set" operations.
|
|
2423
|
+
* On web, IndexedDB will keep the top-level keys along with a null value and this uses up storage and memory.
|
|
2424
|
+
* This method will ensure that keys for null values are removed before an object is written to disk and cache so that all platforms are storing the data in the same efficient way.
|
|
2425
|
+
* @private
|
|
2426
|
+
* @param {*} value
|
|
2427
|
+
* @returns {*}
|
|
2428
|
+
*/
|
|
2429
|
+
function removeNullObjectValues(value) {
|
|
2430
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_0___default().isArray(value) || !underscore__WEBPACK_IMPORTED_MODULE_0___default().isObject(value)) {
|
|
2431
|
+
return value;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
const objectWithoutNullObjectValues = underscore__WEBPACK_IMPORTED_MODULE_0___default().omit(value, (objectValue) => underscore__WEBPACK_IMPORTED_MODULE_0___default().isNull(objectValue));
|
|
2435
|
+
|
|
2436
|
+
return objectWithoutNullObjectValues;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ removeNullObjectValues });
|
|
2440
|
+
|
|
2441
|
+
/***/ }),
|
|
2442
|
+
|
|
2417
2443
|
/***/ "./lib/withOnyx.js":
|
|
2418
2444
|
/*!*************************!*\
|
|
2419
2445
|
!*** ./lib/withOnyx.js ***!
|