react-native-onyx 1.0.120 → 1.0.121
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 +118 -110
- package/dist/web.development.js.map +1 -1
- package/dist/web.min.js.map +1 -1
- package/lib/Logger.js +1 -5
- package/lib/MDTable.js +11 -14
- package/lib/Onyx.d.ts +1 -4
- package/lib/Onyx.js +237 -232
- package/lib/OnyxCache.js +12 -3
- package/lib/Str.js +1 -3
- package/lib/compose.js +6 -2
- package/lib/metrics/PerformanceUtils.js +2 -7
- package/lib/metrics/index.native.js +28 -41
- package/lib/metrics/index.web.js +4 -7
- package/lib/storage/WebStorage.js +5 -10
- package/lib/storage/__mocks__/index.js +2 -2
- package/lib/storage/providers/IDBKeyVal.js +27 -37
- package/lib/storage/providers/SQLiteStorage.js +58 -62
- package/lib/types.d.ts +1 -13
- package/lib/utils.d.ts +2 -6
- package/lib/utils.js +19 -22
- package/lib/withOnyx.d.ts +8 -32
- package/lib/withOnyx.js +37 -34
- package/package.json +6 -3
package/dist/web.development.js
CHANGED
|
@@ -316,12 +316,17 @@ const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) => selecto
|
|
|
316
316
|
* @param {Object} [withOnyxInstanceState]
|
|
317
317
|
* @returns {Object}
|
|
318
318
|
*/
|
|
319
|
-
const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceState) =>
|
|
319
|
+
const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceState) =>
|
|
320
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
321
|
+
collection,
|
|
322
|
+
(finalCollection, item, key) => {
|
|
320
323
|
// eslint-disable-next-line no-param-reassign
|
|
321
324
|
finalCollection[key] = getSubsetOfData(item, selector, withOnyxInstanceState);
|
|
322
325
|
|
|
323
326
|
return finalCollection;
|
|
324
|
-
},
|
|
327
|
+
},
|
|
328
|
+
{});
|
|
329
|
+
|
|
325
330
|
|
|
326
331
|
/**
|
|
327
332
|
* Get some data from the store
|
|
@@ -374,8 +379,7 @@ function getAllKeys() {
|
|
|
374
379
|
}
|
|
375
380
|
|
|
376
381
|
// Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
|
|
377
|
-
const promise = _storage__WEBPACK_IMPORTED_MODULE_5__["default"].getAllKeys().
|
|
378
|
-
then((keys) => {
|
|
382
|
+
const promise = _storage__WEBPACK_IMPORTED_MODULE_5__["default"].getAllKeys().then((keys) => {
|
|
379
383
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keys, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].addKey(key));
|
|
380
384
|
return keys;
|
|
381
385
|
});
|
|
@@ -414,9 +418,7 @@ function isCollectionMemberKey(collectionKey, key) {
|
|
|
414
418
|
* @return {Boolean}
|
|
415
419
|
*/
|
|
416
420
|
function isKeyMatch(configKey, key) {
|
|
417
|
-
return isCollectionKey(configKey) ?
|
|
418
|
-
_Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(key, configKey) :
|
|
419
|
-
configKey === key;
|
|
421
|
+
return isCollectionKey(configKey) ? _Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(key, configKey) : configKey === key;
|
|
420
422
|
}
|
|
421
423
|
|
|
422
424
|
/**
|
|
@@ -451,7 +453,9 @@ function tryGetCachedValue(key) {let mapping = arguments.length > 1 && arguments
|
|
|
451
453
|
return;
|
|
452
454
|
}
|
|
453
455
|
const matchingKeys = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(allCacheKeys, (k) => k.startsWith(key));
|
|
454
|
-
const values = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
456
|
+
const values = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
457
|
+
matchingKeys,
|
|
458
|
+
(finalObject, matchedKey) => {
|
|
455
459
|
const cachedValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getValue(matchedKey);
|
|
456
460
|
if (cachedValue) {
|
|
457
461
|
// This is permissible because we're in the process of constructing the final object in a reduce function.
|
|
@@ -459,7 +463,9 @@ function tryGetCachedValue(key) {let mapping = arguments.length > 1 && arguments
|
|
|
459
463
|
finalObject[matchedKey] = cachedValue;
|
|
460
464
|
}
|
|
461
465
|
return finalObject;
|
|
462
|
-
},
|
|
466
|
+
},
|
|
467
|
+
{});
|
|
468
|
+
|
|
463
469
|
|
|
464
470
|
val = values;
|
|
465
471
|
}
|
|
@@ -547,8 +553,7 @@ function addToEvictionBlockList(key, connectionID) {
|
|
|
547
553
|
* @returns {Promise}
|
|
548
554
|
*/
|
|
549
555
|
function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
550
|
-
return getAllKeys().
|
|
551
|
-
then((keys) => {
|
|
556
|
+
return getAllKeys().then((keys) => {
|
|
552
557
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(evictionAllowList, (safeEvictionKey) => {
|
|
553
558
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keys, (key) => {
|
|
554
559
|
if (!isKeyMatch(safeEvictionKey, key)) {
|
|
@@ -566,11 +571,11 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
566
571
|
* @returns {Object}
|
|
567
572
|
*/
|
|
568
573
|
function getCachedCollection(collectionKey) {
|
|
569
|
-
const collectionMemberKeys = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getAllKeys(),
|
|
570
|
-
(storedKey) => isCollectionMemberKey(collectionKey, storedKey));
|
|
571
|
-
|
|
574
|
+
const collectionMemberKeys = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getAllKeys(), (storedKey) => isCollectionMemberKey(collectionKey, storedKey));
|
|
572
575
|
|
|
573
|
-
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
576
|
+
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
577
|
+
collectionMemberKeys,
|
|
578
|
+
(prev, curr) => {
|
|
574
579
|
const cachedValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].getValue(curr);
|
|
575
580
|
if (!cachedValue) {
|
|
576
581
|
return prev;
|
|
@@ -579,7 +584,9 @@ function getCachedCollection(collectionKey) {
|
|
|
579
584
|
// eslint-disable-next-line no-param-reassign
|
|
580
585
|
prev[curr] = cachedValue;
|
|
581
586
|
return prev;
|
|
582
|
-
},
|
|
587
|
+
},
|
|
588
|
+
{});
|
|
589
|
+
|
|
583
590
|
}
|
|
584
591
|
|
|
585
592
|
/**
|
|
@@ -948,9 +955,7 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
948
955
|
if (mapping.withOnyxInstance && !isCollectionKey(mapping.key)) {
|
|
949
956
|
// All React components subscribing to a key flagged as a safe eviction key must implement the canEvict property.
|
|
950
957
|
if (underscore__WEBPACK_IMPORTED_MODULE_1___default().isUndefined(mapping.canEvict)) {
|
|
951
|
-
throw new Error(
|
|
952
|
-
`Cannot subscribe to safe eviction key '${mapping.key}' without providing a canEvict value.`);
|
|
953
|
-
|
|
958
|
+
throw new Error(`Cannot subscribe to safe eviction key '${mapping.key}' without providing a canEvict value.`);
|
|
954
959
|
}
|
|
955
960
|
|
|
956
961
|
addLastAccessedKey(mapping.key);
|
|
@@ -966,11 +971,17 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
966
971
|
*/
|
|
967
972
|
function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
|
|
968
973
|
Promise.all(underscore__WEBPACK_IMPORTED_MODULE_1___default().map(matchingKeys, (key) => get(key))).
|
|
969
|
-
then((values) =>
|
|
974
|
+
then((values) =>
|
|
975
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
976
|
+
values,
|
|
977
|
+
(finalObject, value, i) => {
|
|
970
978
|
// eslint-disable-next-line no-param-reassign
|
|
971
979
|
finalObject[matchingKeys[i]] = value;
|
|
972
980
|
return finalObject;
|
|
973
|
-
},
|
|
981
|
+
},
|
|
982
|
+
{})).
|
|
983
|
+
|
|
984
|
+
|
|
974
985
|
then((val) => sendDataToConnection(mapping, val, undefined, true));
|
|
975
986
|
}
|
|
976
987
|
|
|
@@ -1018,11 +1029,7 @@ function connect(mapping) {
|
|
|
1018
1029
|
// Performance improvement
|
|
1019
1030
|
// If the mapping is connected to an onyx key that is not a collection
|
|
1020
1031
|
// we can skip the call to getAllKeys() and return an array with a single item
|
|
1021
|
-
if (Boolean(mapping.key) &&
|
|
1022
|
-
typeof mapping.key === 'string' &&
|
|
1023
|
-
!mapping.key.endsWith('_') &&
|
|
1024
|
-
_OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].storageKeys.has(mapping.key))
|
|
1025
|
-
{
|
|
1032
|
+
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !mapping.key.endsWith('_') && _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].storageKeys.has(mapping.key)) {
|
|
1026
1033
|
return [mapping.key];
|
|
1027
1034
|
}
|
|
1028
1035
|
return getAllKeys();
|
|
@@ -1186,7 +1193,7 @@ function reportStorageQuota() {
|
|
|
1186
1193
|
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];}
|
|
1187
1194
|
_Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo(`Failed to save to storage. Error: ${error}. onyxMethod: ${onyxMethod.name}`);
|
|
1188
1195
|
|
|
1189
|
-
if (error && _Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(error.message,
|
|
1196
|
+
if (error && _Str__WEBPACK_IMPORTED_MODULE_7__.startsWith(error.message, "Failed to execute 'put' on 'IDBObjectStore'")) {
|
|
1190
1197
|
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert('Attempted to set invalid data set in Onyx. Please ensure all data is serializable.');
|
|
1191
1198
|
throw error;
|
|
1192
1199
|
}
|
|
@@ -1204,8 +1211,7 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
1204
1211
|
// Remove the least recently viewed key that is not currently being accessed and retry.
|
|
1205
1212
|
_Logger__WEBPACK_IMPORTED_MODULE_6__.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
|
|
1206
1213
|
reportStorageQuota();
|
|
1207
|
-
return remove(keyForRemoval).
|
|
1208
|
-
then(() => onyxMethod(...args));
|
|
1214
|
+
return remove(keyForRemoval).then(() => onyxMethod(...args));
|
|
1209
1215
|
}
|
|
1210
1216
|
|
|
1211
1217
|
/**
|
|
@@ -1340,14 +1346,17 @@ function multiSet(data) {
|
|
|
1340
1346
|
return scheduleSubscriberUpdate(key, val);
|
|
1341
1347
|
});
|
|
1342
1348
|
|
|
1343
|
-
const keyValuePairsWithoutNull = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(
|
|
1349
|
+
const keyValuePairsWithoutNull = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(
|
|
1350
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().map(keyValuePairs, (_ref2) => {let [key, value] = _ref2;
|
|
1344
1351
|
const valueWithoutNull = removeNullValues(key, value);
|
|
1345
1352
|
|
|
1346
1353
|
if (valueWithoutNull === null) {
|
|
1347
1354
|
return;
|
|
1348
1355
|
}
|
|
1349
1356
|
return [key, valueWithoutNull];
|
|
1350
|
-
}),
|
|
1357
|
+
}),
|
|
1358
|
+
Boolean);
|
|
1359
|
+
|
|
1351
1360
|
|
|
1352
1361
|
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiSet(keyValuePairsWithoutNull).
|
|
1353
1362
|
catch((error) => evictStorageAndRetry(error, multiSet, data)).
|
|
@@ -1372,8 +1381,7 @@ function applyMerge(existingValue, changes, shouldRemoveNullObjectValues) {
|
|
|
1372
1381
|
|
|
1373
1382
|
if (underscore__WEBPACK_IMPORTED_MODULE_1___default().some(changes, (underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject))) {
|
|
1374
1383
|
// Object values are then merged one after the other
|
|
1375
|
-
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) => _utils__WEBPACK_IMPORTED_MODULE_9__["default"].fastMerge(modifiedData, change, shouldRemoveNullObjectValues),
|
|
1376
|
-
existingValue || {});
|
|
1384
|
+
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) => _utils__WEBPACK_IMPORTED_MODULE_9__["default"].fastMerge(modifiedData, change, shouldRemoveNullObjectValues), existingValue || {});
|
|
1377
1385
|
}
|
|
1378
1386
|
|
|
1379
1387
|
// If we have anything else we can't merge it so we'll
|
|
@@ -1425,8 +1433,7 @@ function merge(key, changes) {
|
|
|
1425
1433
|
}
|
|
1426
1434
|
mergeQueue[key] = [changes];
|
|
1427
1435
|
|
|
1428
|
-
mergeQueuePromise[key] = get(key).
|
|
1429
|
-
then((existingValue) => {
|
|
1436
|
+
mergeQueuePromise[key] = get(key).then((existingValue) => {
|
|
1430
1437
|
try {
|
|
1431
1438
|
// We first only merge the changes, so we can provide these to the native implementation (SQLite uses only delta changes in "JSON_PATCH" to merge)
|
|
1432
1439
|
// We don't want to remove null values from the "batchedChanges", because SQLite uses them to remove keys from storage natively.
|
|
@@ -1469,8 +1476,7 @@ function merge(key, changes) {
|
|
|
1469
1476
|
return updatePromise;
|
|
1470
1477
|
}
|
|
1471
1478
|
|
|
1472
|
-
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].mergeItem(key, batchedChanges, modifiedData).
|
|
1473
|
-
then(() => updatePromise);
|
|
1479
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].mergeItem(key, batchedChanges, modifiedData).then(() => updatePromise);
|
|
1474
1480
|
} catch (error) {
|
|
1475
1481
|
_Logger__WEBPACK_IMPORTED_MODULE_6__.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
|
|
1476
1482
|
return Promise.resolve();
|
|
@@ -1486,8 +1492,7 @@ function merge(key, changes) {
|
|
|
1486
1492
|
* @returns {Promise}
|
|
1487
1493
|
*/
|
|
1488
1494
|
function initializeWithDefaultKeyStates() {
|
|
1489
|
-
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiGet(underscore__WEBPACK_IMPORTED_MODULE_1___default().keys(defaultKeyStates)).
|
|
1490
|
-
then((pairs) => {
|
|
1495
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiGet(underscore__WEBPACK_IMPORTED_MODULE_1___default().keys(defaultKeyStates)).then((pairs) => {
|
|
1491
1496
|
const asObject = underscore__WEBPACK_IMPORTED_MODULE_1___default().object(pairs);
|
|
1492
1497
|
|
|
1493
1498
|
const merged = _utils__WEBPACK_IMPORTED_MODULE_9__["default"].fastMerge(asObject, defaultKeyStates);
|
|
@@ -1530,8 +1535,7 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1530
1535
|
|
|
1531
1536
|
isClearing = true;
|
|
1532
1537
|
|
|
1533
|
-
return getAllKeys().
|
|
1534
|
-
then((keys) => {
|
|
1538
|
+
return getAllKeys().then((keys) => {
|
|
1535
1539
|
const keysToBeClearedFromStorage = [];
|
|
1536
1540
|
const keyValuesToResetAsCollection = {};
|
|
1537
1541
|
const keyValuesToResetIndividually = {};
|
|
@@ -1588,7 +1592,9 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1588
1592
|
|
|
1589
1593
|
// Remove only the items that we want cleared from storage, and reset others to default
|
|
1590
1594
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keysToBeClearedFromStorage, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_4__["default"].drop(key));
|
|
1591
|
-
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].removeItems(keysToBeClearedFromStorage).
|
|
1595
|
+
return _storage__WEBPACK_IMPORTED_MODULE_5__["default"].removeItems(keysToBeClearedFromStorage).
|
|
1596
|
+
then(() => _storage__WEBPACK_IMPORTED_MODULE_5__["default"].multiSet(defaultKeyValuePairs)).
|
|
1597
|
+
then(() => {
|
|
1592
1598
|
isClearing = false;
|
|
1593
1599
|
_broadcast__WEBPACK_IMPORTED_MODULE_11__.sendMessage({ type: METHOD.CLEAR, keysToPreserve });
|
|
1594
1600
|
return Promise.all(updatePromises);
|
|
@@ -1636,8 +1642,7 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1636
1642
|
return Promise.resolve();
|
|
1637
1643
|
}
|
|
1638
1644
|
|
|
1639
|
-
return getAllKeys().
|
|
1640
|
-
then((persistedKeys) => {
|
|
1645
|
+
return getAllKeys().then((persistedKeys) => {
|
|
1641
1646
|
// Split to keys that exist in storage and keys that don't
|
|
1642
1647
|
const [existingKeys, newKeys] = underscore__WEBPACK_IMPORTED_MODULE_1___default().chain(collection).
|
|
1643
1648
|
pick((value, key) => {
|
|
@@ -1844,10 +1849,14 @@ function init()
|
|
|
1844
1849
|
// We need the value of the collection keys later for checking if a
|
|
1845
1850
|
// key is a collection. We store it in a map for faster lookup.
|
|
1846
1851
|
const collectionValues = underscore__WEBPACK_IMPORTED_MODULE_1___default().values(keys.COLLECTION);
|
|
1847
|
-
onyxCollectionKeyMap = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
1852
|
+
onyxCollectionKeyMap = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
1853
|
+
collectionValues,
|
|
1854
|
+
(acc, val) => {
|
|
1848
1855
|
acc.set(val, true);
|
|
1849
1856
|
return acc;
|
|
1850
|
-
},
|
|
1857
|
+
},
|
|
1858
|
+
new Map());
|
|
1859
|
+
|
|
1851
1860
|
|
|
1852
1861
|
// Set our default key states to use when initializing and clearing Onyx data
|
|
1853
1862
|
defaultKeyStates = initialKeyStates;
|
|
@@ -1856,11 +1865,7 @@ function init()
|
|
|
1856
1865
|
evictionAllowList = safeEvictionKeys;
|
|
1857
1866
|
|
|
1858
1867
|
// Initialize all of our keys with data provided then give green light to any pending connections
|
|
1859
|
-
Promise.all([
|
|
1860
|
-
addAllSafeEvictionKeysToRecentlyAccessedList(),
|
|
1861
|
-
initializeWithDefaultKeyStates()]).
|
|
1862
|
-
|
|
1863
|
-
then(deferredInitTask.resolve);
|
|
1868
|
+
Promise.all([addAllSafeEvictionKeysToRecentlyAccessedList(), initializeWithDefaultKeyStates()]).then(deferredInitTask.resolve);
|
|
1864
1869
|
|
|
1865
1870
|
if (shouldSyncMultipleInstances && underscore__WEBPACK_IMPORTED_MODULE_1___default().isFunction(_storage__WEBPACK_IMPORTED_MODULE_5__["default"].keepInstancesSync)) {
|
|
1866
1871
|
_storage__WEBPACK_IMPORTED_MODULE_5__["default"].keepInstancesSync((key, value) => {
|
|
@@ -1998,8 +2003,17 @@ class OnyxCache {
|
|
|
1998
2003
|
// bind all public methods to prevent problems with `this`
|
|
1999
2004
|
underscore__WEBPACK_IMPORTED_MODULE_0___default().bindAll(
|
|
2000
2005
|
this,
|
|
2001
|
-
'getAllKeys',
|
|
2002
|
-
'
|
|
2006
|
+
'getAllKeys',
|
|
2007
|
+
'getValue',
|
|
2008
|
+
'hasCacheForKey',
|
|
2009
|
+
'addKey',
|
|
2010
|
+
'set',
|
|
2011
|
+
'drop',
|
|
2012
|
+
'merge',
|
|
2013
|
+
'hasPendingTask',
|
|
2014
|
+
'getTaskPromise',
|
|
2015
|
+
'captureTask',
|
|
2016
|
+
'removeLeastRecentlyUsedKeys',
|
|
2003
2017
|
'setRecentKeysLimit');
|
|
2004
2018
|
|
|
2005
2019
|
}
|
|
@@ -2205,9 +2219,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2205
2219
|
* @return {Boolean} Returns true if the haystack starts with the needle.
|
|
2206
2220
|
*/
|
|
2207
2221
|
function startsWith(haystack, needle) {
|
|
2208
|
-
return underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(haystack) &&
|
|
2209
|
-
underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(needle) &&
|
|
2210
|
-
haystack.startsWith(needle);
|
|
2222
|
+
return underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(haystack) && underscore__WEBPACK_IMPORTED_MODULE_0___default().isString(needle) && haystack.startsWith(needle);
|
|
2211
2223
|
}
|
|
2212
2224
|
|
|
2213
2225
|
/**
|
|
@@ -2384,9 +2396,7 @@ function diffObject(object, base) {
|
|
|
2384
2396
|
}
|
|
2385
2397
|
|
|
2386
2398
|
// eslint-disable-next-line no-param-reassign
|
|
2387
|
-
result[key] = underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(value) && underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(comparisonObject[key]) ?
|
|
2388
|
-
changes(value, comparisonObject[key]) :
|
|
2389
|
-
value;
|
|
2399
|
+
result[key] = underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(value) && underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(comparisonObject[key]) ? changes(value, comparisonObject[key]) : value;
|
|
2390
2400
|
});
|
|
2391
2401
|
}
|
|
2392
2402
|
return changes(object, base);
|
|
@@ -2440,7 +2450,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2440
2450
|
/* harmony export */ });
|
|
2441
2451
|
// For web-only implementations of Onyx, this module will just be a no-op
|
|
2442
2452
|
|
|
2443
|
-
function decorateWithMetrics(func) {
|
|
2453
|
+
function decorateWithMetrics(func) {
|
|
2454
|
+
return func;
|
|
2455
|
+
}
|
|
2444
2456
|
function getMetrics() {}
|
|
2445
2457
|
function printMetrics() {}
|
|
2446
2458
|
function resetMetrics() {}
|
|
@@ -2496,17 +2508,13 @@ const webStorage = {
|
|
|
2496
2508
|
*/
|
|
2497
2509
|
keepInstancesSync(onStorageKeyChanged) {
|
|
2498
2510
|
// Override set, remove and clear to raise storage events that we intercept in other tabs
|
|
2499
|
-
this.setItem = (key, value) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].setItem(key, value).
|
|
2500
|
-
then(() => raiseStorageSyncEvent(key));
|
|
2511
|
+
this.setItem = (key, value) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].setItem(key, value).then(() => raiseStorageSyncEvent(key));
|
|
2501
2512
|
|
|
2502
|
-
this.removeItem = (key) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].removeItem(key).
|
|
2503
|
-
then(() => raiseStorageSyncEvent(key));
|
|
2513
|
+
this.removeItem = (key) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].removeItem(key).then(() => raiseStorageSyncEvent(key));
|
|
2504
2514
|
|
|
2505
|
-
this.removeItems = (keys) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].removeItems(keys).
|
|
2506
|
-
then(() => raiseStorageSyncManyKeysEvent(keys));
|
|
2515
|
+
this.removeItems = (keys) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].removeItems(keys).then(() => raiseStorageSyncManyKeysEvent(keys));
|
|
2507
2516
|
|
|
2508
|
-
this.mergeItem = (key, batchedChanges, modifiedData) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].mergeItem(key, batchedChanges, modifiedData).
|
|
2509
|
-
then(() => raiseStorageSyncEvent(key));
|
|
2517
|
+
this.mergeItem = (key, batchedChanges, modifiedData) => _providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].mergeItem(key, batchedChanges, modifiedData).then(() => raiseStorageSyncEvent(key));
|
|
2510
2518
|
|
|
2511
2519
|
// If we just call Storage.clear other tabs will have no idea which keys were available previously
|
|
2512
2520
|
// so that they can call keysChanged for them. That's why we iterate over every key and raise a storage sync
|
|
@@ -2535,8 +2543,7 @@ const webStorage = {
|
|
|
2535
2543
|
}
|
|
2536
2544
|
|
|
2537
2545
|
const onyxKey = event.newValue;
|
|
2538
|
-
_providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].getItem(onyxKey).
|
|
2539
|
-
then((value) => onStorageKeyChanged(onyxKey, value));
|
|
2546
|
+
_providers_IDBKeyVal__WEBPACK_IMPORTED_MODULE_1__["default"].getItem(onyxKey).then((value) => onStorageKeyChanged(onyxKey, value));
|
|
2540
2547
|
});
|
|
2541
2548
|
}
|
|
2542
2549
|
};
|
|
@@ -2608,8 +2615,7 @@ const provider = {
|
|
|
2608
2615
|
* @param {String[]} keysParam
|
|
2609
2616
|
* @return {Promise<Array<[key, value]>>}
|
|
2610
2617
|
*/
|
|
2611
|
-
multiGet: (keysParam) => (0,idb_keyval__WEBPACK_IMPORTED_MODULE_0__.getMany)(keysParam, getCustomStore()).
|
|
2612
|
-
then((values) => underscore__WEBPACK_IMPORTED_MODULE_1___default().map(values, (value, index) => [keysParam[index], value])),
|
|
2618
|
+
multiGet: (keysParam) => (0,idb_keyval__WEBPACK_IMPORTED_MODULE_0__.getMany)(keysParam, getCustomStore()).then((values) => underscore__WEBPACK_IMPORTED_MODULE_1___default().map(values, (value, index) => [keysParam[index], value])),
|
|
2613
2619
|
|
|
2614
2620
|
/**
|
|
2615
2621
|
* Multiple merging of existing and new values in a batch
|
|
@@ -2617,7 +2623,8 @@ const provider = {
|
|
|
2617
2623
|
* This function also removes all nested null values from an object.
|
|
2618
2624
|
* @return {Promise<void>}
|
|
2619
2625
|
*/
|
|
2620
|
-
multiMerge: (pairs) =>
|
|
2626
|
+
multiMerge: (pairs) =>
|
|
2627
|
+
getCustomStore()('readwrite', (store) => {
|
|
2621
2628
|
// Note: we are using the manual store transaction here, to fit the read and update
|
|
2622
2629
|
// of the items in one transaction to achieve best performance.
|
|
2623
2630
|
|
|
@@ -2672,8 +2679,8 @@ const provider = {
|
|
|
2672
2679
|
* @param {String} key
|
|
2673
2680
|
* @return {Promise<*>}
|
|
2674
2681
|
*/
|
|
2675
|
-
getItem: (key) =>
|
|
2676
|
-
|
|
2682
|
+
getItem: (key) =>
|
|
2683
|
+
(0,idb_keyval__WEBPACK_IMPORTED_MODULE_0__.get)(key, getCustomStore())
|
|
2677
2684
|
// idb-keyval returns undefined for missing items, but this needs to return null so that idb-keyval does the same thing as SQLiteStorage.
|
|
2678
2685
|
.then((val) => val === undefined ? null : val),
|
|
2679
2686
|
|
|
@@ -2701,7 +2708,8 @@ const provider = {
|
|
|
2701
2708
|
throw new Error('StorageManager browser API unavailable');
|
|
2702
2709
|
}
|
|
2703
2710
|
|
|
2704
|
-
return window.navigator.storage.
|
|
2711
|
+
return window.navigator.storage.
|
|
2712
|
+
estimate().
|
|
2705
2713
|
then((value) => ({
|
|
2706
2714
|
bytesUsed: value.usage,
|
|
2707
2715
|
bytesRemaining: value.quota - value.usage
|
|
@@ -2732,12 +2740,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2732
2740
|
|
|
2733
2741
|
|
|
2734
2742
|
function areObjectsEmpty(a, b) {
|
|
2735
|
-
return (
|
|
2736
|
-
typeof a === 'object' &&
|
|
2737
|
-
typeof b === 'object' &&
|
|
2738
|
-
underscore__WEBPACK_IMPORTED_MODULE_0___default().isEmpty(a) &&
|
|
2739
|
-
underscore__WEBPACK_IMPORTED_MODULE_0___default().isEmpty(b));
|
|
2740
|
-
|
|
2743
|
+
return typeof a === 'object' && typeof b === 'object' && underscore__WEBPACK_IMPORTED_MODULE_0___default().isEmpty(a) && underscore__WEBPACK_IMPORTED_MODULE_0___default().isEmpty(b);
|
|
2741
2744
|
}
|
|
2742
2745
|
|
|
2743
2746
|
// Mostly copied from https://medium.com/@lubaka.a/how-to-remove-lodash-performance-improvement-b306669ad0e1
|
|
@@ -2745,22 +2748,24 @@ function areObjectsEmpty(a, b) {
|
|
|
2745
2748
|
/**
|
|
2746
2749
|
* @param {mixed} val
|
|
2747
2750
|
* @returns {boolean}
|
|
2748
|
-
*/
|
|
2751
|
+
*/
|
|
2749
2752
|
function isMergeableObject(val) {
|
|
2750
2753
|
const nonNullObject = val != null ? typeof val === 'object' : false;
|
|
2751
|
-
return
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2754
|
+
return (
|
|
2755
|
+
nonNullObject &&
|
|
2756
|
+
Object.prototype.toString.call(val) !== '[object RegExp]' &&
|
|
2757
|
+
Object.prototype.toString.call(val) !== '[object Date]' &&
|
|
2758
|
+
// eslint-disable-next-line rulesdir/prefer-underscore-method
|
|
2759
|
+
!Array.isArray(val));
|
|
2760
|
+
|
|
2756
2761
|
}
|
|
2757
2762
|
|
|
2758
2763
|
/**
|
|
2759
|
-
* @param {Object} target
|
|
2760
|
-
* @param {Object} source
|
|
2761
|
-
* @param {Boolean} shouldRemoveNullObjectValues
|
|
2762
|
-
* @returns {Object}
|
|
2763
|
-
*/
|
|
2764
|
+
* @param {Object} target
|
|
2765
|
+
* @param {Object} source
|
|
2766
|
+
* @param {Boolean} shouldRemoveNullObjectValues
|
|
2767
|
+
* @returns {Object}
|
|
2768
|
+
*/
|
|
2764
2769
|
function mergeObject(target, source) {let shouldRemoveNullObjectValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2765
2770
|
const destination = {};
|
|
2766
2771
|
if (isMergeableObject(target)) {
|
|
@@ -2816,11 +2821,11 @@ function mergeObject(target, source) {let shouldRemoveNullObjectValues = argumen
|
|
|
2816
2821
|
* On native, when merging an existing value with new changes, SQLite will use JSON_PATCH, which removes top-level nullish values.
|
|
2817
2822
|
* To be consistent with the behaviour for merge, we'll also want to remove null values for "set" operations.
|
|
2818
2823
|
*
|
|
2819
|
-
* @param {Object|Array} target
|
|
2820
|
-
* @param {Object|Array} source
|
|
2821
|
-
* @param {Boolean} shouldRemoveNullObjectValues
|
|
2822
|
-
* @returns {Object|Array}
|
|
2823
|
-
*/
|
|
2824
|
+
* @param {Object|Array} target
|
|
2825
|
+
* @param {Object|Array} source
|
|
2826
|
+
* @param {Boolean} shouldRemoveNullObjectValues
|
|
2827
|
+
* @returns {Object|Array}
|
|
2828
|
+
*/
|
|
2824
2829
|
function fastMerge(target, source) {let shouldRemoveNullObjectValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2825
2830
|
// We have to ignore arrays and nullish values here,
|
|
2826
2831
|
// otherwise "mergeObject" will throw an error,
|
|
@@ -2939,11 +2944,7 @@ const getOnyxDataFromState = (state, onyxToStateMapping) => underscore__WEBPACK_
|
|
|
2939
2944
|
* In reality, Onyx.merge() will only update the subscriber after all merges have been batched and the previous value is retrieved via a get() (returns a promise).
|
|
2940
2945
|
* So, we won't use the cache optimization here as it will lead us to arbitrarily defer various actions in the application code.
|
|
2941
2946
|
*/
|
|
2942
|
-
if (
|
|
2943
|
-
value !== undefined &&
|
|
2944
|
-
!_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].hasPendingMergeForKey(key) ||
|
|
2945
|
-
mapping.allowStaleData)
|
|
2946
|
-
{
|
|
2947
|
+
if (value !== undefined && !_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].hasPendingMergeForKey(key) || mapping.allowStaleData) {
|
|
2947
2948
|
// eslint-disable-next-line no-param-reassign
|
|
2948
2949
|
resultObj[propertyName] = value;
|
|
2949
2950
|
}
|
|
@@ -2997,9 +2998,7 @@ const getOnyxDataFromState = (state, onyxToStateMapping) => underscore__WEBPACK_
|
|
|
2997
2998
|
// (eg. if a user switches chats really quickly). In this case, it's much more stable to always look at the changes to prevProp and prevState to derive the key.
|
|
2998
2999
|
// The second case cannot be used all the time because the onyx data doesn't change the first time that `componentDidUpdate()` runs after loading. In this case,
|
|
2999
3000
|
// the `mapping.previousKey` must be used for the comparison or else this logic never detects that onyx data could have changed during the loading process.
|
|
3000
|
-
const previousKey = isFirstTimeUpdatingAfterLoading ?
|
|
3001
|
-
mapping.previousKey :
|
|
3002
|
-
_Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, { ...prevProps, ...prevOnyxDataFromState });
|
|
3001
|
+
const previousKey = isFirstTimeUpdatingAfterLoading ? mapping.previousKey : _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, { ...prevProps, ...prevOnyxDataFromState });
|
|
3003
3002
|
const newKey = _Str__WEBPACK_IMPORTED_MODULE_3__.result(mapping.key, { ...this.props, ...onyxDataFromState });
|
|
3004
3003
|
if (previousKey !== newKey) {
|
|
3005
3004
|
_Onyx__WEBPACK_IMPORTED_MODULE_4__["default"].disconnect(this.activeConnectionIDs[previousKey], previousKey);
|
|
@@ -3077,7 +3076,9 @@ const getOnyxDataFromState = (state, onyxToStateMapping) => underscore__WEBPACK_
|
|
|
3077
3076
|
|
|
3078
3077
|
// Full of hacky workarounds to prevent the race condition described above.
|
|
3079
3078
|
this.setState((prevState) => {
|
|
3080
|
-
const finalState = underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(
|
|
3079
|
+
const finalState = underscore__WEBPACK_IMPORTED_MODULE_2___default().reduce(
|
|
3080
|
+
stateUpdate,
|
|
3081
|
+
(result, value, key) => {
|
|
3081
3082
|
if (key === 'loading') {
|
|
3082
3083
|
return result;
|
|
3083
3084
|
}
|
|
@@ -3099,7 +3100,9 @@ const getOnyxDataFromState = (state, onyxToStateMapping) => underscore__WEBPACK_
|
|
|
3099
3100
|
result[key] = value;
|
|
3100
3101
|
}
|
|
3101
3102
|
return result;
|
|
3102
|
-
},
|
|
3103
|
+
},
|
|
3104
|
+
{});
|
|
3105
|
+
|
|
3103
3106
|
|
|
3104
3107
|
finalState.loading = false;
|
|
3105
3108
|
return finalState;
|
|
@@ -3215,8 +3218,13 @@ const getOnyxDataFromState = (state, onyxToStateMapping) => underscore__WEBPACK_
|
|
|
3215
3218
|
withOnyx.displayName = `withOnyx(${displayName})`;
|
|
3216
3219
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().forwardRef((props, ref) => {
|
|
3217
3220
|
const Component = withOnyx;
|
|
3218
|
-
|
|
3219
|
-
|
|
3221
|
+
return /*#__PURE__*/(
|
|
3222
|
+
react__WEBPACK_IMPORTED_MODULE_1___default().createElement(Component
|
|
3223
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
3224
|
+
, _extends({}, props, {
|
|
3225
|
+
forwardedRef: ref })));
|
|
3226
|
+
|
|
3227
|
+
|
|
3220
3228
|
});
|
|
3221
3229
|
};
|
|
3222
3230
|
}
|