react-native-onyx 1.0.48 → 1.0.50
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/dist/web.development.js +233 -173
- 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 +12 -3
- package/lib/Str.js +29 -0
- package/lib/storage/providers/LocalForage.js +17 -0
- package/lib/storage/providers/SQLiteStorage.js +5 -0
- package/lib/withOnyx.js +2 -2
- package/package.json +1 -3
package/dist/web.development.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
2
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory(require("
|
|
3
|
+
module.exports = factory(require("fast-equals"), require("lodash/get"), require("underscore"), require("localforage"), require("localforage-removeitems"), require("lodash/transform"), require("react"));
|
|
4
4
|
else if(typeof define === 'function' && define.amd)
|
|
5
|
-
define(["
|
|
5
|
+
define(["fast-equals", "lodash/get", "underscore", "localforage", "localforage-removeitems", "lodash/transform", "react"], factory);
|
|
6
6
|
else if(typeof exports === 'object')
|
|
7
|
-
exports["react-native-onyx/web"] = factory(require("
|
|
7
|
+
exports["react-native-onyx/web"] = factory(require("fast-equals"), require("lodash/get"), require("underscore"), require("localforage"), require("localforage-removeitems"), require("lodash/transform"), require("react"));
|
|
8
8
|
else
|
|
9
|
-
root["react-native-onyx/web"] = factory(root["
|
|
10
|
-
})(self, (
|
|
9
|
+
root["react-native-onyx/web"] = factory(root["fast-equals"], root["lodash/get"], root["underscore"], root["localforage"], root["localforage-removeitems"], root["lodash/transform"], root["react"]);
|
|
10
|
+
})(self, (__WEBPACK_EXTERNAL_MODULE_fast_equals__, __WEBPACK_EXTERNAL_MODULE_lodash_get__, __WEBPACK_EXTERNAL_MODULE_underscore__, __WEBPACK_EXTERNAL_MODULE_localforage__, __WEBPACK_EXTERNAL_MODULE_localforage_removeitems__, __WEBPACK_EXTERNAL_MODULE_lodash_transform__, __WEBPACK_EXTERNAL_MODULE_react__) => {
|
|
11
11
|
return /******/ (() => { // webpackBootstrap
|
|
12
12
|
/******/ var __webpack_modules__ = ({
|
|
13
13
|
|
|
@@ -69,20 +69,19 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
69
69
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
70
70
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
71
71
|
/* harmony export */ });
|
|
72
|
-
/* harmony import */ var
|
|
73
|
-
/* harmony import */ var
|
|
74
|
-
/* harmony import */ var
|
|
75
|
-
/* harmony import */ var
|
|
76
|
-
/* harmony import */ var
|
|
77
|
-
/* harmony import */ var
|
|
78
|
-
/* harmony import */ var
|
|
79
|
-
/* harmony import */ var
|
|
80
|
-
/* harmony import */ var
|
|
81
|
-
/* harmony import */ var
|
|
82
|
-
/* harmony import */ var _OnyxCache__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./OnyxCache */ "./lib/OnyxCache.js");
|
|
83
|
-
/* harmony import */ var _createDeferredTask__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js");
|
|
72
|
+
/* harmony import */ var fast_equals__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fast-equals */ "fast-equals");
|
|
73
|
+
/* harmony import */ var fast_equals__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fast_equals__WEBPACK_IMPORTED_MODULE_0__);
|
|
74
|
+
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/get */ "lodash/get");
|
|
75
|
+
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_1__);
|
|
76
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "underscore");
|
|
77
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
|
|
78
|
+
/* harmony import */ var _Logger__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Logger */ "./lib/Logger.js");
|
|
79
|
+
/* harmony import */ var _OnyxCache__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./OnyxCache */ "./lib/OnyxCache.js");
|
|
80
|
+
/* harmony import */ var _Str__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Str */ "./lib/Str.js");
|
|
81
|
+
/* harmony import */ var _createDeferredTask__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js");
|
|
84
82
|
/* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./fastMerge */ "./lib/fastMerge.js");
|
|
85
83
|
/* harmony import */ var _metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./metrics/PerformanceUtils */ "./lib/metrics/PerformanceUtils.js");
|
|
84
|
+
/* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./storage */ "./lib/storage/index.web.js");
|
|
86
85
|
/* eslint-disable no-continue */
|
|
87
86
|
|
|
88
87
|
|
|
@@ -127,7 +126,7 @@ const evictionBlocklist = {};
|
|
|
127
126
|
let defaultKeyStates = {};
|
|
128
127
|
|
|
129
128
|
// Connections can be made before `Onyx.init`. They would wait for this task before resolving
|
|
130
|
-
const deferredInitTask = (0,
|
|
129
|
+
const deferredInitTask = (0,_createDeferredTask__WEBPACK_IMPORTED_MODULE_3__["default"])();
|
|
131
130
|
|
|
132
131
|
/**
|
|
133
132
|
* Uses a selector string or function to return a simplified version of sourceData
|
|
@@ -138,9 +137,9 @@ const deferredInitTask = (0,_createDeferredTask__WEBPACK_IMPORTED_MODULE_4__["de
|
|
|
138
137
|
* If it's a function, it is passed the sourceData and it should return the simplified data
|
|
139
138
|
* @returns {Mixed}
|
|
140
139
|
*/
|
|
141
|
-
const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) =>
|
|
140
|
+
const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) => underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(selector) ?
|
|
142
141
|
selector(sourceData, withOnyxInstanceState) :
|
|
143
|
-
|
|
142
|
+
lodash_get__WEBPACK_IMPORTED_MODULE_1___default()(sourceData, selector);
|
|
144
143
|
|
|
145
144
|
/**
|
|
146
145
|
* Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
|
|
@@ -151,7 +150,7 @@ lodash_get__WEBPACK_IMPORTED_MODULE_3___default()(sourceData, selector);
|
|
|
151
150
|
* @param {Object} [withOnyxInstanceState]
|
|
152
151
|
* @returns {Object}
|
|
153
152
|
*/
|
|
154
|
-
const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceState) =>
|
|
153
|
+
const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceState) => underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(collection, (finalCollection, item, key) => {
|
|
155
154
|
// eslint-disable-next-line no-param-reassign
|
|
156
155
|
finalCollection[key] = getSubsetOfData(item, selector, withOnyxInstanceState);
|
|
157
156
|
|
|
@@ -167,26 +166,26 @@ const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceStat
|
|
|
167
166
|
*/
|
|
168
167
|
function get(key) {
|
|
169
168
|
// When we already have the value in cache - resolve right away
|
|
170
|
-
if (
|
|
171
|
-
return Promise.resolve(
|
|
169
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].hasCacheForKey(key)) {
|
|
170
|
+
return Promise.resolve(_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getValue(key));
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
const taskName = `get:${key}`;
|
|
175
174
|
|
|
176
175
|
// When a value retrieving task for this key is still running hook to it
|
|
177
|
-
if (
|
|
178
|
-
return
|
|
176
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].hasPendingTask(taskName)) {
|
|
177
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getTaskPromise(taskName);
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
// Otherwise retrieve the value from storage and capture a promise to aid concurrent usages
|
|
182
|
-
const promise =
|
|
181
|
+
const promise = _storage__WEBPACK_IMPORTED_MODULE_5__["default"].getItem(key).
|
|
183
182
|
then((val) => {
|
|
184
|
-
|
|
183
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].set(key, val);
|
|
185
184
|
return val;
|
|
186
185
|
}).
|
|
187
|
-
catch((err) =>
|
|
186
|
+
catch((err) => _Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`));
|
|
188
187
|
|
|
189
|
-
return
|
|
188
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].captureTask(taskName, promise);
|
|
190
189
|
}
|
|
191
190
|
|
|
192
191
|
/**
|
|
@@ -196,7 +195,7 @@ function get(key) {
|
|
|
196
195
|
*/
|
|
197
196
|
function getAllKeys() {
|
|
198
197
|
// When we've already read stored keys, resolve right away
|
|
199
|
-
const storedKeys =
|
|
198
|
+
const storedKeys = _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getAllKeys();
|
|
200
199
|
if (storedKeys.length > 0) {
|
|
201
200
|
return Promise.resolve(storedKeys);
|
|
202
201
|
}
|
|
@@ -204,18 +203,18 @@ function getAllKeys() {
|
|
|
204
203
|
const taskName = 'getAllKeys';
|
|
205
204
|
|
|
206
205
|
// When a value retrieving task for all keys is still running hook to it
|
|
207
|
-
if (
|
|
208
|
-
return
|
|
206
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].hasPendingTask(taskName)) {
|
|
207
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getTaskPromise(taskName);
|
|
209
208
|
}
|
|
210
209
|
|
|
211
210
|
// Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
|
|
212
|
-
const promise =
|
|
211
|
+
const promise = _storage__WEBPACK_IMPORTED_MODULE_5__["default"].getAllKeys().
|
|
213
212
|
then((keys) => {
|
|
214
|
-
|
|
213
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keys, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].addKey(key));
|
|
215
214
|
return keys;
|
|
216
215
|
});
|
|
217
216
|
|
|
218
|
-
return
|
|
217
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].captureTask(taskName, promise);
|
|
219
218
|
}
|
|
220
219
|
|
|
221
220
|
/**
|
|
@@ -227,7 +226,7 @@ function getAllKeys() {
|
|
|
227
226
|
* @returns {Boolean}
|
|
228
227
|
*/
|
|
229
228
|
function isCollectionKey(key) {
|
|
230
|
-
return
|
|
229
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().contains(underscore__WEBPACK_IMPORTED_MODULE_2___default().values(onyxKeys.COLLECTION), key);
|
|
231
230
|
}
|
|
232
231
|
|
|
233
232
|
/**
|
|
@@ -236,7 +235,7 @@ function isCollectionKey(key) {
|
|
|
236
235
|
* @returns {Boolean}
|
|
237
236
|
*/
|
|
238
237
|
function isCollectionMemberKey(collectionKey, key) {
|
|
239
|
-
return
|
|
238
|
+
return _Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(key, collectionKey) && key.length > collectionKey.length;
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
/**
|
|
@@ -250,7 +249,7 @@ function isCollectionMemberKey(collectionKey, key) {
|
|
|
250
249
|
*/
|
|
251
250
|
function isKeyMatch(configKey, key) {
|
|
252
251
|
return isCollectionKey(configKey) ?
|
|
253
|
-
|
|
252
|
+
_Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(key, configKey) :
|
|
254
253
|
configKey === key;
|
|
255
254
|
}
|
|
256
255
|
|
|
@@ -263,7 +262,7 @@ function isKeyMatch(configKey, key) {
|
|
|
263
262
|
* @returns {Boolean}
|
|
264
263
|
*/
|
|
265
264
|
function isSafeEvictionKey(testKey) {
|
|
266
|
-
return
|
|
265
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().some(evictionAllowList, (key) => isKeyMatch(key, testKey));
|
|
267
266
|
}
|
|
268
267
|
|
|
269
268
|
/**
|
|
@@ -273,7 +272,7 @@ function isSafeEvictionKey(testKey) {
|
|
|
273
272
|
* @param {String} key
|
|
274
273
|
*/
|
|
275
274
|
function removeLastAccessedKey(key) {
|
|
276
|
-
recentlyAccessedKeys =
|
|
275
|
+
recentlyAccessedKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().without(recentlyAccessedKeys, key);
|
|
277
276
|
}
|
|
278
277
|
|
|
279
278
|
/**
|
|
@@ -303,7 +302,7 @@ function addLastAccessedKey(key) {
|
|
|
303
302
|
* @param {Number} connectionID
|
|
304
303
|
*/
|
|
305
304
|
function removeFromEvictionBlockList(key, connectionID) {
|
|
306
|
-
evictionBlocklist[key] =
|
|
305
|
+
evictionBlocklist[key] = underscore__WEBPACK_IMPORTED_MODULE_2___default().without(evictionBlocklist[key] || [], connectionID);
|
|
307
306
|
|
|
308
307
|
// Remove the key if there are no more subscribers
|
|
309
308
|
if (evictionBlocklist[key].length === 0) {
|
|
@@ -340,8 +339,8 @@ function addToEvictionBlockList(key, connectionID) {
|
|
|
340
339
|
function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
341
340
|
return getAllKeys().
|
|
342
341
|
then((keys) => {
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(evictionAllowList, (safeEvictionKey) => {
|
|
343
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keys, (key) => {
|
|
345
344
|
if (!isKeyMatch(safeEvictionKey, key)) {
|
|
346
345
|
return;
|
|
347
346
|
}
|
|
@@ -357,12 +356,12 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
357
356
|
* @returns {Object}
|
|
358
357
|
*/
|
|
359
358
|
function getCachedCollection(collectionKey) {
|
|
360
|
-
const collectionMemberKeys =
|
|
359
|
+
const collectionMemberKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().filter(_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getAllKeys(),
|
|
361
360
|
(storedKey) => isCollectionMemberKey(collectionKey, storedKey));
|
|
362
361
|
|
|
363
362
|
|
|
364
|
-
return
|
|
365
|
-
const cachedValue =
|
|
363
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(collectionMemberKeys, (prev, curr) => {
|
|
364
|
+
const cachedValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getValue(curr);
|
|
366
365
|
if (!cachedValue) {
|
|
367
366
|
return prev;
|
|
368
367
|
}
|
|
@@ -384,7 +383,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
384
383
|
// We are iterating over all subscribers similar to keyChanged(). However, we are looking for subscribers who are subscribing to either a collection key or
|
|
385
384
|
// individual collection key member for the collection that is being updated. It is important to note that the collection parameter cane be a PARTIAL collection
|
|
386
385
|
// and does not represent all of the combined keys and values for a collection key. It is just the "new" data that was merged in via mergeCollection().
|
|
387
|
-
const stateMappingKeys =
|
|
386
|
+
const stateMappingKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(callbackToStateMapping);
|
|
388
387
|
for (let i = 0; i < stateMappingKeys.length; i++) {
|
|
389
388
|
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
|
|
390
389
|
if (!subscriber) {
|
|
@@ -392,7 +391,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
392
391
|
}
|
|
393
392
|
|
|
394
393
|
// Skip iteration if we do not have a collection key or a collection member key on this subscriber
|
|
395
|
-
if (!
|
|
394
|
+
if (!_Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(subscriber.key, collectionKey)) {
|
|
396
395
|
continue;
|
|
397
396
|
}
|
|
398
397
|
|
|
@@ -411,7 +410,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
411
410
|
const cachedCollection = getCachedCollection(collectionKey);
|
|
412
411
|
|
|
413
412
|
// Regular Onyx.connect() subscriber found.
|
|
414
|
-
if (
|
|
413
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(subscriber.callback)) {
|
|
415
414
|
// If they are subscribed to the collection key and using waitForCollectionCallback then we'll
|
|
416
415
|
// send the whole cached collection.
|
|
417
416
|
if (isSubscribedToCollectionKey) {
|
|
@@ -422,7 +421,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
422
421
|
|
|
423
422
|
// If they are not using waitForCollectionCallback then we notify the subscriber with
|
|
424
423
|
// the new merged data but only for any keys in the partial collection.
|
|
425
|
-
const dataKeys =
|
|
424
|
+
const dataKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(partialCollection);
|
|
426
425
|
for (let j = 0; j < dataKeys.length; j++) {
|
|
427
426
|
const dataKey = dataKeys[j];
|
|
428
427
|
subscriber.callback(cachedCollection[dataKey], dataKey);
|
|
@@ -452,7 +451,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
452
451
|
const previousData = prevState[subscriber.statePropertyName];
|
|
453
452
|
const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector, subscriber.withOnyxInstance.state);
|
|
454
453
|
|
|
455
|
-
if (!(0,
|
|
454
|
+
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(previousData, newData)) {
|
|
456
455
|
return {
|
|
457
456
|
[subscriber.statePropertyName]: newData
|
|
458
457
|
};
|
|
@@ -463,8 +462,8 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
463
462
|
}
|
|
464
463
|
|
|
465
464
|
subscriber.withOnyxInstance.setState((prevState) => {
|
|
466
|
-
const finalCollection =
|
|
467
|
-
const dataKeys =
|
|
465
|
+
const finalCollection = underscore__WEBPACK_IMPORTED_MODULE_2___default().clone(prevState[subscriber.statePropertyName] || {});
|
|
466
|
+
const dataKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(partialCollection);
|
|
468
467
|
for (let j = 0; j < dataKeys.length; j++) {
|
|
469
468
|
const dataKey = dataKeys[j];
|
|
470
469
|
finalCollection[dataKey] = cachedCollection[dataKey];
|
|
@@ -483,7 +482,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
483
482
|
// However, we only want to update this subscriber if the partial data contains a change.
|
|
484
483
|
// Otherwise, we would update them with a value they already have and trigger an unnecessary re-render.
|
|
485
484
|
const dataFromCollection = partialCollection[subscriber.key];
|
|
486
|
-
if (
|
|
485
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isUndefined(dataFromCollection)) {
|
|
487
486
|
continue;
|
|
488
487
|
}
|
|
489
488
|
|
|
@@ -494,7 +493,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
494
493
|
subscriber.withOnyxInstance.setState((prevState) => {
|
|
495
494
|
const prevData = prevState[subscriber.statePropertyName];
|
|
496
495
|
const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector, subscriber.withOnyxInstance.state);
|
|
497
|
-
if (!(0,
|
|
496
|
+
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(prevData, newData)) {
|
|
498
497
|
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_8__.logSetStateCall(subscriber, prevData, newData, 'keysChanged', collectionKey);
|
|
499
498
|
return {
|
|
500
499
|
[subscriber.statePropertyName]: newData
|
|
@@ -536,7 +535,7 @@ function keysChanged(collectionKey, partialCollection) {
|
|
|
536
535
|
*/
|
|
537
536
|
function keyChanged(key, data, canUpdateSubscriber) {
|
|
538
537
|
// Add or remove this key from the recentlyAccessedKeys lists
|
|
539
|
-
if (!
|
|
538
|
+
if (!underscore__WEBPACK_IMPORTED_MODULE_2___default().isNull(data)) {
|
|
540
539
|
addLastAccessedKey(key);
|
|
541
540
|
} else {
|
|
542
541
|
removeLastAccessedKey(key);
|
|
@@ -545,15 +544,15 @@ function keyChanged(key, data, canUpdateSubscriber) {
|
|
|
545
544
|
// We are iterating over all subscribers to see if they are interested in the key that has just changed. If the subscriber's key is a collection key then we will
|
|
546
545
|
// notify them if the key that changed is a collection member. Or if it is a regular key notify them when there is an exact match. Depending on whether the subscriber
|
|
547
546
|
// was connected via withOnyx we will call setState() directly on the withOnyx instance. If it is a regular connection we will pass the data to the provided callback.
|
|
548
|
-
const stateMappingKeys =
|
|
547
|
+
const stateMappingKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(callbackToStateMapping);
|
|
549
548
|
for (let i = 0; i < stateMappingKeys.length; i++) {
|
|
550
549
|
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
|
|
551
|
-
if (!subscriber || !isKeyMatch(subscriber.key, key) ||
|
|
550
|
+
if (!subscriber || !isKeyMatch(subscriber.key, key) || underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(canUpdateSubscriber) && !canUpdateSubscriber(subscriber)) {
|
|
552
551
|
continue;
|
|
553
552
|
}
|
|
554
553
|
|
|
555
554
|
// Subscriber is a regular call to connect() and provided a callback
|
|
556
|
-
if (
|
|
555
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(subscriber.callback)) {
|
|
557
556
|
if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) {
|
|
558
557
|
const cachedCollection = getCachedCollection(subscriber.key);
|
|
559
558
|
cachedCollection[key] = data;
|
|
@@ -581,7 +580,7 @@ function keyChanged(key, data, canUpdateSubscriber) {
|
|
|
581
580
|
...prevData,
|
|
582
581
|
...newData
|
|
583
582
|
};
|
|
584
|
-
if (!(0,
|
|
583
|
+
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(prevData, prevDataWithNewData)) {
|
|
585
584
|
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_8__.logSetStateCall(subscriber, prevData, newData, 'keyChanged', key);
|
|
586
585
|
return {
|
|
587
586
|
[subscriber.statePropertyName]: prevDataWithNewData
|
|
@@ -612,7 +611,7 @@ function keyChanged(key, data, canUpdateSubscriber) {
|
|
|
612
611
|
subscriber.withOnyxInstance.setState((prevState) => {
|
|
613
612
|
const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.state);
|
|
614
613
|
const newValue = getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.state);
|
|
615
|
-
if (!(0,
|
|
614
|
+
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(previousValue, newValue)) {
|
|
616
615
|
return {
|
|
617
616
|
[subscriber.statePropertyName]: newValue
|
|
618
617
|
};
|
|
@@ -680,7 +679,7 @@ function sendDataToConnection(mapping, val, matchedKey) {
|
|
|
680
679
|
return;
|
|
681
680
|
}
|
|
682
681
|
|
|
683
|
-
if (
|
|
682
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(mapping.callback)) {
|
|
684
683
|
mapping.callback(val, matchedKey);
|
|
685
684
|
}
|
|
686
685
|
}
|
|
@@ -698,11 +697,11 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
698
697
|
}
|
|
699
698
|
|
|
700
699
|
// Try to free some cache whenever we connect to a safe eviction key
|
|
701
|
-
|
|
700
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].removeLeastRecentlyUsedKeys();
|
|
702
701
|
|
|
703
702
|
if (mapping.withOnyxInstance && !isCollectionKey(mapping.key)) {
|
|
704
703
|
// All React components subscribing to a key flagged as a safe eviction key must implement the canEvict property.
|
|
705
|
-
if (
|
|
704
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isUndefined(mapping.canEvict)) {
|
|
706
705
|
throw new Error(
|
|
707
706
|
`Cannot subscribe to safe eviction key '${mapping.key}' without providing a canEvict value.`);
|
|
708
707
|
|
|
@@ -720,8 +719,8 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
720
719
|
* @param {Object} mapping
|
|
721
720
|
*/
|
|
722
721
|
function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
|
|
723
|
-
Promise.all(
|
|
724
|
-
then((values) =>
|
|
722
|
+
Promise.all(underscore__WEBPACK_IMPORTED_MODULE_2___default().map(matchingKeys, (key) => get(key))).
|
|
723
|
+
then((values) => underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(values, (finalObject, value, i) => {
|
|
725
724
|
// eslint-disable-next-line no-param-reassign
|
|
726
725
|
finalObject[matchingKeys[i]] = value;
|
|
727
726
|
return finalObject;
|
|
@@ -772,7 +771,7 @@ function connect(mapping) {
|
|
|
772
771
|
// We search all the keys in storage to see if any are a "match" for the subscriber we are connecting so that we
|
|
773
772
|
// can send data back to the subscriber. Note that multiple keys can match as a subscriber could either be
|
|
774
773
|
// subscribed to a "collection key" or a single key.
|
|
775
|
-
const matchingKeys =
|
|
774
|
+
const matchingKeys = underscore__WEBPACK_IMPORTED_MODULE_2___default().filter(keys, (key) => isKeyMatch(mapping.key, key));
|
|
776
775
|
|
|
777
776
|
// If the key being connected to does not exist we initialize the value with null. For subscribers that connected
|
|
778
777
|
// directly via connect() they will simply get a null value sent to them without any information about which key matched
|
|
@@ -786,7 +785,7 @@ function connect(mapping) {
|
|
|
786
785
|
// When using a callback subscriber we will either trigger the provided callback for each key we find or combine all values
|
|
787
786
|
// into an object and just make a single call. The latter behavior is enabled by providing a waitForCollectionCallback key
|
|
788
787
|
// combined with a subscription to a collection key.
|
|
789
|
-
if (
|
|
788
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(mapping.callback)) {
|
|
790
789
|
if (isCollectionKey(mapping.key)) {
|
|
791
790
|
if (mapping.waitForCollectionCallback) {
|
|
792
791
|
getCollectionDataAndSendAsObject(matchingKeys, mapping);
|
|
@@ -887,9 +886,9 @@ function notifyCollectionSubscribersOnNextTick(key, value) {
|
|
|
887
886
|
* @return {Promise}
|
|
888
887
|
*/
|
|
889
888
|
function remove(key) {
|
|
890
|
-
|
|
889
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].drop(key);
|
|
891
890
|
notifySubscribersOnNextTick(key, null);
|
|
892
|
-
return
|
|
891
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].removeItem(key);
|
|
893
892
|
}
|
|
894
893
|
|
|
895
894
|
/**
|
|
@@ -904,23 +903,23 @@ function remove(key) {
|
|
|
904
903
|
* @return {Promise}
|
|
905
904
|
*/
|
|
906
905
|
function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {args[_key - 2] = arguments[_key];}
|
|
907
|
-
|
|
906
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo(`Handled error: ${error}`);
|
|
908
907
|
|
|
909
|
-
if (error &&
|
|
910
|
-
|
|
908
|
+
if (error && _Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(error.message, 'Failed to execute \'put\' on \'IDBObjectStore\'')) {
|
|
909
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert('Attempted to set invalid data set in Onyx. Please ensure all data is serializable.');
|
|
911
910
|
throw error;
|
|
912
911
|
}
|
|
913
912
|
|
|
914
913
|
// Find the first key that we can remove that has no subscribers in our blocklist
|
|
915
|
-
const keyForRemoval =
|
|
914
|
+
const keyForRemoval = underscore__WEBPACK_IMPORTED_MODULE_2___default().find(recentlyAccessedKeys, (key) => !evictionBlocklist[key]);
|
|
916
915
|
|
|
917
916
|
if (!keyForRemoval) {
|
|
918
|
-
|
|
917
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert('Out of storage. But found no acceptable keys to remove.');
|
|
919
918
|
throw error;
|
|
920
919
|
}
|
|
921
920
|
|
|
922
921
|
// Remove the least recently viewed key that is not currently being accessed and retry.
|
|
923
|
-
|
|
922
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
|
|
924
923
|
return remove(keyForRemoval).
|
|
925
924
|
then(() => onyxMethod(...args));
|
|
926
925
|
}
|
|
@@ -934,29 +933,29 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
934
933
|
* @returns {Promise}
|
|
935
934
|
*/
|
|
936
935
|
function set(key, value) {
|
|
937
|
-
if (
|
|
936
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isNull(value)) {
|
|
938
937
|
return remove(key);
|
|
939
938
|
}
|
|
940
939
|
|
|
941
940
|
// eslint-disable-next-line no-use-before-define
|
|
942
941
|
if (hasPendingMergeForKey(key)) {
|
|
943
|
-
|
|
942
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert(`Onyx.set() called after Onyx.merge() for key: ${key}. It is recommended to use set() or merge() not both.`);
|
|
944
943
|
}
|
|
945
944
|
|
|
946
945
|
// If the value in the cache is the same as what we have then do not update subscribers unless they
|
|
947
946
|
// have initWithStoredValues: false then they MUST get all updates even if nothing has changed.
|
|
948
|
-
if (!
|
|
949
|
-
|
|
947
|
+
if (!_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].hasValueChanged(key, value)) {
|
|
948
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].addToAccessedKeys(key);
|
|
950
949
|
notifySubscribersOnNextTick(key, value, (subscriber) => subscriber.initWithStoredValues === false);
|
|
951
950
|
return Promise.resolve();
|
|
952
951
|
}
|
|
953
952
|
|
|
954
953
|
// Adds the key to cache when it's not available
|
|
955
|
-
|
|
954
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].set(key, value);
|
|
956
955
|
notifySubscribersOnNextTick(key, value);
|
|
957
956
|
|
|
958
957
|
// Write the thing to persistent storage, which will trigger a storage event for any other tabs open on this domain
|
|
959
|
-
return
|
|
958
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].setItem(key, value).
|
|
960
959
|
catch((error) => evictStorageAndRetry(error, set, key, value));
|
|
961
960
|
}
|
|
962
961
|
|
|
@@ -969,7 +968,7 @@ function set(key, value) {
|
|
|
969
968
|
* @return {Array} an array of key - value pairs <[key, value]>
|
|
970
969
|
*/
|
|
971
970
|
function prepareKeyValuePairsForStorage(data) {
|
|
972
|
-
return
|
|
971
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().map(data, (value, key) => [key, value]);
|
|
973
972
|
}
|
|
974
973
|
|
|
975
974
|
/**
|
|
@@ -983,13 +982,13 @@ function prepareKeyValuePairsForStorage(data) {
|
|
|
983
982
|
function multiSet(data) {
|
|
984
983
|
const keyValuePairs = prepareKeyValuePairsForStorage(data);
|
|
985
984
|
|
|
986
|
-
|
|
985
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(data, (val, key) => {
|
|
987
986
|
// Update cache and optimistically inform subscribers on the next tick
|
|
988
|
-
|
|
987
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].set(key, val);
|
|
989
988
|
notifySubscribersOnNextTick(key, val);
|
|
990
989
|
});
|
|
991
990
|
|
|
992
|
-
return
|
|
991
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiSet(keyValuePairs).
|
|
993
992
|
catch((error) => evictStorageAndRetry(error, multiSet, data));
|
|
994
993
|
}
|
|
995
994
|
|
|
@@ -1019,18 +1018,18 @@ function hasPendingMergeForKey(key) {
|
|
|
1019
1018
|
*/
|
|
1020
1019
|
function applyMerge(key, data) {
|
|
1021
1020
|
const mergeValues = mergeQueue[key];
|
|
1022
|
-
if (
|
|
1021
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isArray(data) || underscore__WEBPACK_IMPORTED_MODULE_2___default().every(mergeValues, (underscore__WEBPACK_IMPORTED_MODULE_2___default().isArray))) {
|
|
1023
1022
|
// Array values will always just concatenate
|
|
1024
1023
|
// more items onto the end of the array
|
|
1025
|
-
return
|
|
1024
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(mergeValues, (modifiedData, mergeValue) => [
|
|
1026
1025
|
...modifiedData,
|
|
1027
1026
|
...mergeValue],
|
|
1028
1027
|
data || []);
|
|
1029
1028
|
}
|
|
1030
1029
|
|
|
1031
|
-
if (
|
|
1030
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isObject(data) || underscore__WEBPACK_IMPORTED_MODULE_2___default().every(mergeValues, (underscore__WEBPACK_IMPORTED_MODULE_2___default().isObject))) {
|
|
1032
1031
|
// Object values are merged one after the other
|
|
1033
|
-
return
|
|
1032
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(mergeValues, (modifiedData, mergeValue) => {
|
|
1034
1033
|
// lodash adds a small overhead so we don't use it here
|
|
1035
1034
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
1036
1035
|
const newData = Object.assign({}, (0,_fastMerge__WEBPACK_IMPORTED_MODULE_9__["default"])(modifiedData, mergeValue));
|
|
@@ -1038,13 +1037,13 @@ function applyMerge(key, data) {
|
|
|
1038
1037
|
// We will also delete any object keys that are undefined or null.
|
|
1039
1038
|
// Deleting keys is not supported by AsyncStorage so we do it this way.
|
|
1040
1039
|
// Remove all first level keys that are explicitly set to null.
|
|
1041
|
-
return
|
|
1040
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(newData, (value, finalObjectKey) => underscore__WEBPACK_IMPORTED_MODULE_2___default().isNull(mergeValue[finalObjectKey]));
|
|
1042
1041
|
}, data || {});
|
|
1043
1042
|
}
|
|
1044
1043
|
|
|
1045
1044
|
// If we have anything else we can't merge it so we'll
|
|
1046
1045
|
// simply return the last value that was queued
|
|
1047
|
-
return
|
|
1046
|
+
return underscore__WEBPACK_IMPORTED_MODULE_2___default().last(mergeValues);
|
|
1048
1047
|
}
|
|
1049
1048
|
|
|
1050
1049
|
/**
|
|
@@ -1087,7 +1086,7 @@ function merge(key, value) {
|
|
|
1087
1086
|
|
|
1088
1087
|
return set(key, modifiedData);
|
|
1089
1088
|
} catch (error) {
|
|
1090
|
-
|
|
1089
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
|
|
1091
1090
|
}
|
|
1092
1091
|
|
|
1093
1092
|
return Promise.resolve();
|
|
@@ -1100,13 +1099,13 @@ function merge(key, value) {
|
|
|
1100
1099
|
* @returns {Promise}
|
|
1101
1100
|
*/
|
|
1102
1101
|
function initializeWithDefaultKeyStates() {
|
|
1103
|
-
return
|
|
1102
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiGet(underscore__WEBPACK_IMPORTED_MODULE_2___default().keys(defaultKeyStates)).
|
|
1104
1103
|
then((pairs) => {
|
|
1105
|
-
const asObject =
|
|
1104
|
+
const asObject = underscore__WEBPACK_IMPORTED_MODULE_2___default().object(pairs);
|
|
1106
1105
|
|
|
1107
1106
|
const merged = (0,_fastMerge__WEBPACK_IMPORTED_MODULE_9__["default"])(asObject, defaultKeyStates);
|
|
1108
|
-
|
|
1109
|
-
|
|
1107
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].merge(merged);
|
|
1108
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(merged, (val, key) => keyChanged(key, val));
|
|
1110
1109
|
});
|
|
1111
1110
|
}
|
|
1112
1111
|
|
|
@@ -1144,19 +1143,19 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1144
1143
|
// status, or activeClients need to remain in Onyx even when signed out)
|
|
1145
1144
|
// 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them
|
|
1146
1145
|
// to null would cause unknown behavior)
|
|
1147
|
-
|
|
1148
|
-
const isKeyToPreserve =
|
|
1149
|
-
const isDefaultKey =
|
|
1146
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keys, (key) => {
|
|
1147
|
+
const isKeyToPreserve = underscore__WEBPACK_IMPORTED_MODULE_2___default().contains(keysToPreserve, key);
|
|
1148
|
+
const isDefaultKey = underscore__WEBPACK_IMPORTED_MODULE_2___default().has(defaultKeyStates, key);
|
|
1150
1149
|
|
|
1151
1150
|
// If the key is being removed or reset to default:
|
|
1152
1151
|
// 1. Update it in the cache
|
|
1153
1152
|
// 2. Figure out whether it is a collection key or not,
|
|
1154
1153
|
// since collection key subscribers need to be updated differently
|
|
1155
1154
|
if (!isKeyToPreserve) {
|
|
1156
|
-
const oldValue =
|
|
1157
|
-
const newValue =
|
|
1155
|
+
const oldValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getValue(key);
|
|
1156
|
+
const newValue = underscore__WEBPACK_IMPORTED_MODULE_2___default().get(defaultKeyStates, key, null);
|
|
1158
1157
|
if (newValue !== oldValue) {
|
|
1159
|
-
|
|
1158
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].set(key, newValue);
|
|
1160
1159
|
const collectionKey = key.substring(0, key.indexOf('_') + 1);
|
|
1161
1160
|
if (collectionKey) {
|
|
1162
1161
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
@@ -1178,18 +1177,18 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1178
1177
|
});
|
|
1179
1178
|
|
|
1180
1179
|
// Notify the subscribers for each key/value group so they can receive the new values
|
|
1181
|
-
|
|
1180
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keyValuesToResetIndividually, (value, key) => {
|
|
1182
1181
|
notifySubscribersOnNextTick(key, value);
|
|
1183
1182
|
});
|
|
1184
|
-
|
|
1183
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keyValuesToResetAsCollection, (value, key) => {
|
|
1185
1184
|
notifyCollectionSubscribersOnNextTick(key, value);
|
|
1186
1185
|
});
|
|
1187
1186
|
|
|
1188
|
-
const defaultKeyValuePairs =
|
|
1187
|
+
const defaultKeyValuePairs = underscore__WEBPACK_IMPORTED_MODULE_2___default().pairs(underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(defaultKeyStates, keysToPreserve));
|
|
1189
1188
|
|
|
1190
1189
|
// Remove only the items that we want cleared from storage, and reset others to default
|
|
1191
|
-
|
|
1192
|
-
return
|
|
1190
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(keysToBeClearedFromStorage, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].drop(key));
|
|
1191
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].removeItems(keysToBeClearedFromStorage).then(() => _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiSet(defaultKeyValuePairs));
|
|
1193
1192
|
});
|
|
1194
1193
|
}
|
|
1195
1194
|
|
|
@@ -1208,13 +1207,13 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1208
1207
|
* @returns {Promise}
|
|
1209
1208
|
*/
|
|
1210
1209
|
function mergeCollection(collectionKey, collection) {
|
|
1211
|
-
if (!
|
|
1212
|
-
|
|
1210
|
+
if (!underscore__WEBPACK_IMPORTED_MODULE_2___default().isObject(collection) || underscore__WEBPACK_IMPORTED_MODULE_2___default().isArray(collection) || underscore__WEBPACK_IMPORTED_MODULE_2___default().isEmpty(collection)) {
|
|
1211
|
+
_Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo('mergeCollection() called with invalid or empty value. Skipping this update.');
|
|
1213
1212
|
return Promise.resolve();
|
|
1214
1213
|
}
|
|
1215
1214
|
|
|
1216
1215
|
// Confirm all the collection keys belong to the same parent
|
|
1217
|
-
|
|
1216
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(collection, (_data, dataKey) => {
|
|
1218
1217
|
if (isKeyMatch(collectionKey, dataKey)) {
|
|
1219
1218
|
return;
|
|
1220
1219
|
}
|
|
@@ -1225,13 +1224,13 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1225
1224
|
return getAllKeys().
|
|
1226
1225
|
then((persistedKeys) => {
|
|
1227
1226
|
// Split to keys that exist in storage and keys that don't
|
|
1228
|
-
const [existingKeys, newKeys] =
|
|
1227
|
+
const [existingKeys, newKeys] = underscore__WEBPACK_IMPORTED_MODULE_2___default().chain(collection).
|
|
1229
1228
|
keys().
|
|
1230
1229
|
partition((key) => persistedKeys.includes(key)).
|
|
1231
1230
|
value();
|
|
1232
1231
|
|
|
1233
|
-
const existingKeyCollection =
|
|
1234
|
-
const newCollection =
|
|
1232
|
+
const existingKeyCollection = underscore__WEBPACK_IMPORTED_MODULE_2___default().pick(collection, existingKeys);
|
|
1233
|
+
const newCollection = underscore__WEBPACK_IMPORTED_MODULE_2___default().pick(collection, newKeys);
|
|
1235
1234
|
const keyValuePairsForExistingCollection = prepareKeyValuePairsForStorage(existingKeyCollection);
|
|
1236
1235
|
const keyValuePairsForNewCollection = prepareKeyValuePairsForStorage(newCollection);
|
|
1237
1236
|
|
|
@@ -1240,17 +1239,17 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1240
1239
|
// New keys will be added via multiSet while existing keys will be updated using multiMerge
|
|
1241
1240
|
// This is because setting a key that doesn't exist yet with multiMerge will throw errors
|
|
1242
1241
|
if (keyValuePairsForExistingCollection.length > 0) {
|
|
1243
|
-
promises.push(
|
|
1242
|
+
promises.push(_storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiMerge(keyValuePairsForExistingCollection));
|
|
1244
1243
|
}
|
|
1245
1244
|
|
|
1246
1245
|
if (keyValuePairsForNewCollection.length > 0) {
|
|
1247
|
-
promises.push(
|
|
1246
|
+
promises.push(_storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiSet(keyValuePairsForNewCollection));
|
|
1248
1247
|
}
|
|
1249
1248
|
|
|
1250
1249
|
// Prefill cache if necessary by calling get() on any existing keys and then merge original data to cache
|
|
1251
1250
|
// and update all subscribers
|
|
1252
|
-
Promise.all(
|
|
1253
|
-
|
|
1251
|
+
Promise.all(underscore__WEBPACK_IMPORTED_MODULE_2___default().map(existingKeys, get)).then(() => {
|
|
1252
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].merge(collection);
|
|
1254
1253
|
keysChanged(collectionKey, collection);
|
|
1255
1254
|
});
|
|
1256
1255
|
|
|
@@ -1267,11 +1266,11 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1267
1266
|
*/
|
|
1268
1267
|
function update(data) {
|
|
1269
1268
|
// First, validate the Onyx object is in the format we expect
|
|
1270
|
-
|
|
1271
|
-
if (!
|
|
1269
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(data, (_ref) => {let { onyxMethod, key } = _ref;
|
|
1270
|
+
if (!underscore__WEBPACK_IMPORTED_MODULE_2___default().contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION], onyxMethod)) {
|
|
1272
1271
|
throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
|
|
1273
1272
|
}
|
|
1274
|
-
if (onyxMethod !== METHOD.CLEAR && !
|
|
1273
|
+
if (onyxMethod !== METHOD.CLEAR && !underscore__WEBPACK_IMPORTED_MODULE_2___default().isString(key)) {
|
|
1275
1274
|
throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`);
|
|
1276
1275
|
}
|
|
1277
1276
|
});
|
|
@@ -1279,7 +1278,7 @@ function update(data) {
|
|
|
1279
1278
|
const promises = [];
|
|
1280
1279
|
let clearPromise = Promise.resolve();
|
|
1281
1280
|
|
|
1282
|
-
|
|
1281
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(data, (_ref2) => {let { onyxMethod, key, value } = _ref2;
|
|
1283
1282
|
switch (onyxMethod) {
|
|
1284
1283
|
case METHOD.SET:
|
|
1285
1284
|
promises.push(() => set(key, value));
|
|
@@ -1298,7 +1297,15 @@ function update(data) {
|
|
|
1298
1297
|
|
|
1299
1298
|
});
|
|
1300
1299
|
|
|
1301
|
-
return clearPromise.then(() => Promise.all(
|
|
1300
|
+
return clearPromise.then(() => Promise.all(underscore__WEBPACK_IMPORTED_MODULE_2___default().map(promises, (p) => p())));
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* When set these keys will not be persisted to storage
|
|
1305
|
+
* @param {string[]} keyList
|
|
1306
|
+
*/
|
|
1307
|
+
function setMemoryOnlyKeys(keyList) {
|
|
1308
|
+
_storage__WEBPACK_IMPORTED_MODULE_5__["default"].setMemoryOnlyKeys(keyList);
|
|
1302
1309
|
}
|
|
1303
1310
|
|
|
1304
1311
|
/**
|
|
@@ -1346,7 +1353,7 @@ function init()
|
|
|
1346
1353
|
}
|
|
1347
1354
|
|
|
1348
1355
|
if (maxCachedKeysCount > 0) {
|
|
1349
|
-
|
|
1356
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].setRecentKeysLimit(maxCachedKeysCount);
|
|
1350
1357
|
}
|
|
1351
1358
|
|
|
1352
1359
|
// Let Onyx know about all of our keys
|
|
@@ -1365,9 +1372,9 @@ function init()
|
|
|
1365
1372
|
|
|
1366
1373
|
then(deferredInitTask.resolve);
|
|
1367
1374
|
|
|
1368
|
-
if (shouldSyncMultipleInstances &&
|
|
1369
|
-
|
|
1370
|
-
|
|
1375
|
+
if (shouldSyncMultipleInstances && underscore__WEBPACK_IMPORTED_MODULE_2___default().isFunction(_storage__WEBPACK_IMPORTED_MODULE_5__["default"].keepInstancesSync)) {
|
|
1376
|
+
_storage__WEBPACK_IMPORTED_MODULE_5__["default"].keepInstancesSync((key, value) => {
|
|
1377
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].set(key, value);
|
|
1371
1378
|
keyChanged(key, value);
|
|
1372
1379
|
});
|
|
1373
1380
|
}
|
|
@@ -1384,11 +1391,12 @@ const Onyx = {
|
|
|
1384
1391
|
clear,
|
|
1385
1392
|
getAllKeys,
|
|
1386
1393
|
init,
|
|
1387
|
-
registerLogger:
|
|
1394
|
+
registerLogger: _Logger__WEBPACK_IMPORTED_MODULE_6__.registerLogger,
|
|
1388
1395
|
addToEvictionBlockList,
|
|
1389
1396
|
removeFromEvictionBlockList,
|
|
1390
1397
|
isSafeEvictionKey,
|
|
1391
|
-
METHOD
|
|
1398
|
+
METHOD,
|
|
1399
|
+
setMemoryOnlyKeys
|
|
1392
1400
|
};
|
|
1393
1401
|
|
|
1394
1402
|
/**
|
|
@@ -1664,6 +1672,52 @@ const instance = new OnyxCache();
|
|
|
1664
1672
|
|
|
1665
1673
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (instance);
|
|
1666
1674
|
|
|
1675
|
+
/***/ }),
|
|
1676
|
+
|
|
1677
|
+
/***/ "./lib/Str.js":
|
|
1678
|
+
/*!********************!*\
|
|
1679
|
+
!*** ./lib/Str.js ***!
|
|
1680
|
+
\********************/
|
|
1681
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1682
|
+
|
|
1683
|
+
"use strict";
|
|
1684
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1685
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1686
|
+
/* harmony export */ "result": () => (/* binding */ result),
|
|
1687
|
+
/* harmony export */ "startsWith": () => (/* binding */ startsWith)
|
|
1688
|
+
/* harmony export */ });
|
|
1689
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "underscore");
|
|
1690
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
|
|
1691
|
+
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Returns true if the haystack begins with the needle
|
|
1695
|
+
*
|
|
1696
|
+
* @param {String} haystack The full string to be searched
|
|
1697
|
+
* @param {String} needle The case-sensitive string to search for
|
|
1698
|
+
* @return {Boolean} Returns true if the haystack starts with the needle.
|
|
1699
|
+
*/
|
|
1700
|
+
function startsWith(haystack, needle) {
|
|
1701
|
+
return underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(haystack) &&
|
|
1702
|
+
underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(needle) &&
|
|
1703
|
+
haystack.startsWith(needle);
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* Checks if parameter is a string or function.
|
|
1708
|
+
* If it is a string, then we will just return it.
|
|
1709
|
+
* If it is a function, then we will call it with
|
|
1710
|
+
* any additional arguments and return the result.
|
|
1711
|
+
*
|
|
1712
|
+
* @param {String|Function} parameter
|
|
1713
|
+
* @returns {*}
|
|
1714
|
+
*/
|
|
1715
|
+
function result(parameter) {for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {args[_key - 1] = arguments[_key];}
|
|
1716
|
+
return underscore__WEBPACK_IMPORTED_MODULE_0___default().isFunction(parameter) ? parameter(...args) : parameter;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
|
|
1720
|
+
|
|
1667
1721
|
/***/ }),
|
|
1668
1722
|
|
|
1669
1723
|
/***/ "./lib/SyncQueue.js":
|
|
@@ -2087,7 +2141,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2087
2141
|
/* harmony import */ var localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! localforage-removeitems */ "localforage-removeitems");
|
|
2088
2142
|
/* harmony import */ var localforage_removeitems__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__);
|
|
2089
2143
|
/* harmony import */ var _SyncQueue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../SyncQueue */ "./lib/SyncQueue.js");
|
|
2090
|
-
/* harmony import */ var
|
|
2144
|
+
/* harmony import */ var _Str__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../Str */ "./lib/Str.js");
|
|
2145
|
+
/* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../fastMerge */ "./lib/fastMerge.js");
|
|
2091
2146
|
/**
|
|
2092
2147
|
* @file
|
|
2093
2148
|
* The storage provider based on localforage allows us to store most anything in its
|
|
@@ -2100,12 +2155,18 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2100
2155
|
|
|
2101
2156
|
|
|
2102
2157
|
|
|
2158
|
+
|
|
2103
2159
|
(0,localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__.extendPrototype)((localforage__WEBPACK_IMPORTED_MODULE_0___default()));
|
|
2104
2160
|
|
|
2105
2161
|
localforage__WEBPACK_IMPORTED_MODULE_0___default().config({
|
|
2106
2162
|
name: 'OnyxDB'
|
|
2107
2163
|
});
|
|
2108
2164
|
|
|
2165
|
+
/**
|
|
2166
|
+
* Keys that will not ever be persisted to disk.
|
|
2167
|
+
*/
|
|
2168
|
+
let memoryOnlyKeys = [];
|
|
2169
|
+
|
|
2109
2170
|
const provider = {
|
|
2110
2171
|
/**
|
|
2111
2172
|
* Writing very quickly to IndexedDB causes performance issues and can lock up the page and lead to jank.
|
|
@@ -2113,6 +2174,10 @@ const provider = {
|
|
|
2113
2174
|
* to the next.
|
|
2114
2175
|
*/
|
|
2115
2176
|
setItemQueue: new _SyncQueue__WEBPACK_IMPORTED_MODULE_3__["default"]((_ref) => {let { key, value, shouldMerge } = _ref;
|
|
2177
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_1___default().find(memoryOnlyKeys, (noCacheKey) => _Str__WEBPACK_IMPORTED_MODULE_4__.startsWith(key, noCacheKey))) {
|
|
2178
|
+
return Promise.resolve();
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2116
2181
|
if (shouldMerge) {
|
|
2117
2182
|
return localforage__WEBPACK_IMPORTED_MODULE_0___default().getItem(key).
|
|
2118
2183
|
then((existingValue) => {
|
|
@@ -2120,7 +2185,7 @@ const provider = {
|
|
|
2120
2185
|
|
|
2121
2186
|
// lodash adds a small overhead so we don't use it here
|
|
2122
2187
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
2123
|
-
? Object.assign({}, (0,
|
|
2188
|
+
? Object.assign({}, (0,_fastMerge__WEBPACK_IMPORTED_MODULE_5__["default"])(existingValue, value)) :
|
|
2124
2189
|
value;
|
|
2125
2190
|
return localforage__WEBPACK_IMPORTED_MODULE_0___default().setItem(key, newValue);
|
|
2126
2191
|
});
|
|
@@ -2214,6 +2279,13 @@ const provider = {
|
|
|
2214
2279
|
*/
|
|
2215
2280
|
setItem(key, value) {
|
|
2216
2281
|
return this.setItemQueue.push({ key, value });
|
|
2282
|
+
},
|
|
2283
|
+
|
|
2284
|
+
/**
|
|
2285
|
+
* @param {string[]} keyList
|
|
2286
|
+
*/
|
|
2287
|
+
setMemoryOnlyKeys(keyList) {
|
|
2288
|
+
memoryOnlyKeys = keyList;
|
|
2217
2289
|
}
|
|
2218
2290
|
};
|
|
2219
2291
|
|
|
@@ -2232,15 +2304,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2232
2304
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2233
2305
|
/* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)
|
|
2234
2306
|
/* harmony export */ });
|
|
2235
|
-
/* harmony import */ var
|
|
2236
|
-
/* harmony import */ var
|
|
2237
|
-
/* harmony import */ var
|
|
2238
|
-
/* harmony import */ var
|
|
2239
|
-
/* harmony import */ var
|
|
2240
|
-
/* harmony import */ var
|
|
2241
|
-
/* harmony import */ var expensify_common_lib_str__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! expensify-common/lib/str */ "expensify-common/lib/str");
|
|
2242
|
-
/* harmony import */ var expensify_common_lib_str__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(expensify_common_lib_str__WEBPACK_IMPORTED_MODULE_3__);
|
|
2307
|
+
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js");
|
|
2308
|
+
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_0__);
|
|
2309
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ "react");
|
|
2310
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
|
|
2311
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "underscore");
|
|
2312
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
|
|
2243
2313
|
/* harmony import */ var _Onyx__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Onyx */ "./lib/Onyx.js");
|
|
2314
|
+
/* harmony import */ var _Str__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Str */ "./lib/Str.js");
|
|
2244
2315
|
function _extends() {_extends = Object.assign ? Object.assign.bind() : function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};return _extends.apply(this, arguments);} /**
|
|
2245
2316
|
* This is a higher order component that provides the ability to map a state property directly to
|
|
2246
2317
|
* something in Onyx (a key/value store). That way, as soon as data in Onyx changes, the state will be set and the view
|
|
@@ -2264,13 +2335,13 @@ function getDisplayName(component) {
|
|
|
2264
2335
|
|
|
2265
2336
|
/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__(mapOnyxToState) {
|
|
2266
2337
|
// A list of keys that must be present in tempState before we can render the WrappedComponent
|
|
2267
|
-
const requiredKeysForInit =
|
|
2338
|
+
const requiredKeysForInit = underscore__WEBPACK_IMPORTED_MODULE_2___default().chain(mapOnyxToState).
|
|
2268
2339
|
omit((config) => config.initWithStoredValues === false).
|
|
2269
2340
|
keys().
|
|
2270
2341
|
value();
|
|
2271
2342
|
return (WrappedComponent) => {
|
|
2272
2343
|
const displayName = getDisplayName(WrappedComponent);
|
|
2273
|
-
class withOnyx extends (
|
|
2344
|
+
class withOnyx extends (react__WEBPACK_IMPORTED_MODULE_1___default().Component) {
|
|
2274
2345
|
constructor(props) {
|
|
2275
2346
|
super(props);
|
|
2276
2347
|
|
|
@@ -2291,7 +2362,7 @@ function getDisplayName(component) {
|
|
|
2291
2362
|
|
|
2292
2363
|
componentDidMount() {
|
|
2293
2364
|
// Subscribe each of the state properties to the proper Onyx key
|
|
2294
|
-
|
|
2365
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(mapOnyxToState, (mapping, propertyName) => {
|
|
2295
2366
|
this.connectMappingToOnyx(mapping, propertyName);
|
|
2296
2367
|
});
|
|
2297
2368
|
this.checkEvictableKeys();
|
|
@@ -2300,9 +2371,9 @@ function getDisplayName(component) {
|
|
|
2300
2371
|
componentDidUpdate(prevProps) {
|
|
2301
2372
|
// If any of the mappings use data from the props, then when the props change, all the
|
|
2302
2373
|
// connections need to be reconnected with the new props
|
|
2303
|
-
|
|
2304
|
-
const previousKey =
|
|
2305
|
-
const newKey =
|
|
2374
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(mapOnyxToState, (mapping, propertyName) => {
|
|
2375
|
+
const previousKey = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, prevProps);
|
|
2376
|
+
const newKey = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, this.props);
|
|
2306
2377
|
|
|
2307
2378
|
if (previousKey !== newKey) {
|
|
2308
2379
|
_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].disconnect(this.activeConnectionIDs[previousKey], previousKey);
|
|
@@ -2315,8 +2386,8 @@ function getDisplayName(component) {
|
|
|
2315
2386
|
|
|
2316
2387
|
componentWillUnmount() {
|
|
2317
2388
|
// Disconnect everything from Onyx
|
|
2318
|
-
|
|
2319
|
-
const key =
|
|
2389
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(mapOnyxToState, (mapping) => {
|
|
2390
|
+
const key = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, this.props);
|
|
2320
2391
|
const connectionID = this.activeConnectionIDs[key];
|
|
2321
2392
|
_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].disconnect(connectionID, key);
|
|
2322
2393
|
});
|
|
@@ -2339,7 +2410,7 @@ function getDisplayName(component) {
|
|
|
2339
2410
|
this.tempState[statePropertyName] = val;
|
|
2340
2411
|
|
|
2341
2412
|
// All state keys should exist and at least have a value of null
|
|
2342
|
-
if (
|
|
2413
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().some(requiredKeysForInit, (key) => underscore__WEBPACK_IMPORTED_MODULE_2___default().isUndefined(this.tempState[key]))) {
|
|
2343
2414
|
return;
|
|
2344
2415
|
}
|
|
2345
2416
|
|
|
@@ -2356,13 +2427,13 @@ function getDisplayName(component) {
|
|
|
2356
2427
|
// We will add this key to our list of recently accessed keys
|
|
2357
2428
|
// if the canEvict function returns true. This is necessary criteria
|
|
2358
2429
|
// we MUST use to specify if a key can be removed or not.
|
|
2359
|
-
|
|
2360
|
-
if (
|
|
2430
|
+
underscore__WEBPACK_IMPORTED_MODULE_2___default().each(mapOnyxToState, (mapping) => {
|
|
2431
|
+
if (underscore__WEBPACK_IMPORTED_MODULE_2___default().isUndefined(mapping.canEvict)) {
|
|
2361
2432
|
return;
|
|
2362
2433
|
}
|
|
2363
2434
|
|
|
2364
|
-
const canEvict =
|
|
2365
|
-
const key =
|
|
2435
|
+
const canEvict = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.canEvict, this.props);
|
|
2436
|
+
const key = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, this.props);
|
|
2366
2437
|
|
|
2367
2438
|
if (!_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].isSafeEvictionKey(key)) {
|
|
2368
2439
|
throw new Error(`canEvict can't be used on key '${key}'. This key must explicitly be flagged as safe for removal by adding it to Onyx.init({safeEvictionKeys: []}).`);
|
|
@@ -2387,7 +2458,7 @@ function getDisplayName(component) {
|
|
|
2387
2458
|
* component
|
|
2388
2459
|
*/
|
|
2389
2460
|
connectMappingToOnyx(mapping, statePropertyName) {
|
|
2390
|
-
const key =
|
|
2461
|
+
const key = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, this.props);
|
|
2391
2462
|
|
|
2392
2463
|
// eslint-disable-next-line rulesdir/prefer-onyx-connect-in-libs
|
|
2393
2464
|
this.activeConnectionIDs[key] = _Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].connect({
|
|
@@ -2406,15 +2477,15 @@ function getDisplayName(component) {
|
|
|
2406
2477
|
|
|
2407
2478
|
// Remove any internal state properties used by withOnyx
|
|
2408
2479
|
// that should not be passed to a wrapped component
|
|
2409
|
-
let stateToPass =
|
|
2410
|
-
stateToPass =
|
|
2480
|
+
let stateToPass = underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(this.state, 'loading');
|
|
2481
|
+
stateToPass = underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(stateToPass, (value) => underscore__WEBPACK_IMPORTED_MODULE_2___default().isNull(value));
|
|
2411
2482
|
|
|
2412
2483
|
// Remove any null values so that React replaces them with default props
|
|
2413
|
-
const propsToPass =
|
|
2484
|
+
const propsToPass = underscore__WEBPACK_IMPORTED_MODULE_2___default().omit(this.props, (value) => underscore__WEBPACK_IMPORTED_MODULE_2___default().isNull(value));
|
|
2414
2485
|
|
|
2415
2486
|
// Spreading props and state is necessary in an HOC where the data cannot be predicted
|
|
2416
2487
|
return /*#__PURE__*/(
|
|
2417
|
-
|
|
2488
|
+
react__WEBPACK_IMPORTED_MODULE_1___default().createElement(WrappedComponent
|
|
2418
2489
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
2419
2490
|
, _extends({}, propsToPass,
|
|
2420
2491
|
|
|
@@ -2426,19 +2497,19 @@ function getDisplayName(component) {
|
|
|
2426
2497
|
}
|
|
2427
2498
|
|
|
2428
2499
|
withOnyx.propTypes = {
|
|
2429
|
-
forwardedRef:
|
|
2430
|
-
(
|
|
2431
|
-
|
|
2500
|
+
forwardedRef: prop_types__WEBPACK_IMPORTED_MODULE_0___default().oneOfType([
|
|
2501
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_0___default().func),
|
|
2502
|
+
prop_types__WEBPACK_IMPORTED_MODULE_0___default().shape({ current: prop_types__WEBPACK_IMPORTED_MODULE_0___default().instanceOf((react__WEBPACK_IMPORTED_MODULE_1___default().Component)) })])
|
|
2432
2503
|
|
|
2433
2504
|
};
|
|
2434
2505
|
withOnyx.defaultProps = {
|
|
2435
2506
|
forwardedRef: undefined
|
|
2436
2507
|
};
|
|
2437
2508
|
withOnyx.displayName = `withOnyx(${displayName})`;
|
|
2438
|
-
return /*#__PURE__*/
|
|
2509
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().forwardRef((props, ref) => {
|
|
2439
2510
|
const Component = withOnyx;
|
|
2440
2511
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
2441
|
-
return /*#__PURE__*/
|
|
2512
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(Component, _extends({}, props, { forwardedRef: ref }));
|
|
2442
2513
|
});
|
|
2443
2514
|
};
|
|
2444
2515
|
}
|
|
@@ -3515,17 +3586,6 @@ if (false) {} else {
|
|
|
3515
3586
|
}
|
|
3516
3587
|
|
|
3517
3588
|
|
|
3518
|
-
/***/ }),
|
|
3519
|
-
|
|
3520
|
-
/***/ "expensify-common/lib/str":
|
|
3521
|
-
/*!*******************************************!*\
|
|
3522
|
-
!*** external "expensify-common/lib/str" ***!
|
|
3523
|
-
\*******************************************/
|
|
3524
|
-
/***/ ((module) => {
|
|
3525
|
-
|
|
3526
|
-
"use strict";
|
|
3527
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_expensify_common_lib_str__;
|
|
3528
|
-
|
|
3529
3589
|
/***/ }),
|
|
3530
3590
|
|
|
3531
3591
|
/***/ "fast-equals":
|