react-native-onyx 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +14 -0
- package/README.md +4 -6
- package/dist/web.development.js +100 -61
- 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/MDTable.js +1 -1
- package/lib/Onyx.js +91 -53
- package/lib/OnyxCache.js +10 -9
- package/lib/compose.js +1 -0
- package/lib/metrics/index.native.js +7 -7
- package/lib/storage/providers/LocalForage.js +2 -2
- package/lib/withOnyx.js +2 -2
- package/package.json +16 -3
- package/web.js +2 -2
package/API.md
CHANGED
|
@@ -33,6 +33,9 @@ applied in the order they were called. Note: <code>Onyx.set()</code> calls do no
|
|
|
33
33
|
<dt><a href="#mergeCollection">mergeCollection(collectionKey, collection)</a> ⇒ <code>Promise</code></dt>
|
|
34
34
|
<dd><p>Merges a collection based on their keys</p>
|
|
35
35
|
</dd>
|
|
36
|
+
<dt><a href="#update">update(data)</a></dt>
|
|
37
|
+
<dd><p>Insert API responses and lifecycle data into Onyx</p>
|
|
38
|
+
</dd>
|
|
36
39
|
<dt><a href="#init">init([options])</a></dt>
|
|
37
40
|
<dd><p>Initialize the store with actions and listening for storage events</p>
|
|
38
41
|
</dd>
|
|
@@ -158,6 +161,17 @@ Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
|
|
|
158
161
|
[`${ONYXKEYS.COLLECTION.REPORT}2`]: report2,
|
|
159
162
|
});
|
|
160
163
|
```
|
|
164
|
+
<a name="update"></a>
|
|
165
|
+
|
|
166
|
+
## update(data)
|
|
167
|
+
Insert API responses and lifecycle data into Onyx
|
|
168
|
+
|
|
169
|
+
**Kind**: global function
|
|
170
|
+
|
|
171
|
+
| Param | Type | Description |
|
|
172
|
+
| --- | --- | --- |
|
|
173
|
+
| data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge'), key: string, value: *} |
|
|
174
|
+
|
|
161
175
|
<a name="init"></a>
|
|
162
176
|
|
|
163
177
|
## init([options])
|
package/README.md
CHANGED
|
@@ -17,12 +17,10 @@ Persistent storage solution wrapped in a Pub/Sub library.
|
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Onyx is published to [`npm`](https://www.npmjs.com/package/react-native-onyx)
|
|
21
21
|
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
"react-native-onyx": "git+https://github.com/Expensify/react-native-onyx.git#ccb64c738b8bbe933b8997eb177f864e5139bd8d"
|
|
25
|
-
}
|
|
22
|
+
```shell
|
|
23
|
+
npm install react-native-onyx --save
|
|
26
24
|
```
|
|
27
25
|
|
|
28
26
|
## Initialization
|
|
@@ -253,6 +251,6 @@ To quickly test small changes you can directly go to `node_modules/react-native-
|
|
|
253
251
|
To continuously work on Onyx we have to set up a task that copies content to parent project's `node_modules/react-native-onyx`:
|
|
254
252
|
1. Work on Onyx feature or a fix
|
|
255
253
|
2. Save files
|
|
256
|
-
3. Optional: run `npm build
|
|
254
|
+
3. Optional: run `npm build` (if you're working or want to test on a non react-native project)
|
|
257
255
|
- `npm link` would actually work outside of `react-native` and it can be used to link Onyx locally for a web only project
|
|
258
256
|
4. Copy Onyx to consumer project's `node_modules/react-native-onyx`
|
package/dist/web.development.js
CHANGED
|
@@ -493,10 +493,9 @@ var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/inte
|
|
|
493
493
|
var _str = _interopRequireDefault(__webpack_require__(/*! expensify-common/lib/str */ "expensify-common/lib/str"));
|
|
494
494
|
var _merge = _interopRequireDefault(__webpack_require__(/*! lodash/merge */ "lodash/merge"));
|
|
495
495
|
var _storage = _interopRequireDefault(__webpack_require__(/*! ./storage */ "./lib/storage/index.web.js"));
|
|
496
|
-
|
|
497
|
-
var _Logger = __webpack_require__(/*! ./Logger */ "./lib/Logger.js");
|
|
496
|
+
var Logger = _interopRequireWildcard(__webpack_require__(/*! ./Logger */ "./lib/Logger.js"));
|
|
498
497
|
var _OnyxCache = _interopRequireDefault(__webpack_require__(/*! ./OnyxCache */ "./lib/OnyxCache.js"));
|
|
499
|
-
var _createDeferredTask = _interopRequireDefault(__webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js"));
|
|
498
|
+
var _createDeferredTask = _interopRequireDefault(__webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js"));function _getRequireWildcardCache(nodeInterop) {if (typeof WeakMap !== "function") return null;var cacheBabelInterop = new WeakMap();var cacheNodeInterop = new WeakMap();return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) {return nodeInterop ? cacheNodeInterop : cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj, nodeInterop) {if (!nodeInterop && obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache(nodeInterop);if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}
|
|
500
499
|
|
|
501
500
|
// Keeps track of the last connectionID that was used so we can keep incrementing it
|
|
502
501
|
var lastConnectionID = 0;
|
|
@@ -550,7 +549,7 @@ function get(key) {
|
|
|
550
549
|
_OnyxCache.default.set(key, val);
|
|
551
550
|
return val;
|
|
552
551
|
}).
|
|
553
|
-
catch(function (err) {return
|
|
552
|
+
catch(function (err) {return Logger.logInfo("Unable to get item from persistent storage. Key: " + key + " Error: " + err);});
|
|
554
553
|
|
|
555
554
|
return _OnyxCache.default.captureTask(taskName, promise);
|
|
556
555
|
}
|
|
@@ -699,9 +698,10 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
699
698
|
then(function (keys) {
|
|
700
699
|
_underscore.default.each(evictionAllowList, function (safeEvictionKey) {
|
|
701
700
|
_underscore.default.each(keys, function (key) {
|
|
702
|
-
if (isKeyMatch(safeEvictionKey, key)) {
|
|
703
|
-
|
|
701
|
+
if (!isKeyMatch(safeEvictionKey, key)) {
|
|
702
|
+
return;
|
|
704
703
|
}
|
|
704
|
+
addLastAccessedKey(key);
|
|
705
705
|
});
|
|
706
706
|
});
|
|
707
707
|
});
|
|
@@ -749,7 +749,6 @@ function keysChanged(collectionKey, collection) {
|
|
|
749
749
|
|
|
750
750
|
if (isSubscribedToCollectionKey) {
|
|
751
751
|
if (_underscore.default.isFunction(subscriber.callback)) {
|
|
752
|
-
// eslint-disable-next-line no-use-before-define
|
|
753
752
|
var cachedCollection = getCachedCollection(collectionKey);
|
|
754
753
|
_underscore.default.each(collection, function (data, dataKey) {
|
|
755
754
|
subscriber.callback(cachedCollection[dataKey], dataKey);
|
|
@@ -808,29 +807,31 @@ function keyChanged(key, data) {
|
|
|
808
807
|
|
|
809
808
|
// Find all subscribers that were added with connect() and trigger the callback or setState() with the new data
|
|
810
809
|
_underscore.default.each(callbackToStateMapping, function (subscriber) {
|
|
811
|
-
if (subscriber
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
810
|
+
if (!subscriber || !isKeyMatch(subscriber.key, key)) {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
815
813
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
814
|
+
if (_underscore.default.isFunction(subscriber.callback)) {
|
|
815
|
+
subscriber.callback(data, key);
|
|
816
|
+
}
|
|
819
817
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
var collection = _underscore.default.clone(prevState[subscriber.statePropertyName] || {});
|
|
824
|
-
collection[key] = data;
|
|
825
|
-
return (0, _defineProperty2.default)({},
|
|
826
|
-
subscriber.statePropertyName, collection);
|
|
818
|
+
if (!subscriber.withOnyxInstance) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
827
821
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
subscriber.statePropertyName
|
|
822
|
+
// Check if we are subscribing to a collection key and add this item as a collection
|
|
823
|
+
if (isCollectionKey(subscriber.key)) {
|
|
824
|
+
subscriber.withOnyxInstance.setState(function (prevState) {
|
|
825
|
+
var collection = _underscore.default.clone(prevState[subscriber.statePropertyName] || {});
|
|
826
|
+
collection[key] = data;
|
|
827
|
+
return (0, _defineProperty2.default)({},
|
|
828
|
+
subscriber.statePropertyName, collection);
|
|
829
|
+
|
|
830
|
+
});
|
|
831
|
+
} else {
|
|
832
|
+
subscriber.withOnyxInstance.setState((0, _defineProperty2.default)({},
|
|
833
|
+
subscriber.statePropertyName, data));
|
|
832
834
|
|
|
833
|
-
}
|
|
834
835
|
}
|
|
835
836
|
});
|
|
836
837
|
}
|
|
@@ -895,21 +896,23 @@ function connect(mapping) {
|
|
|
895
896
|
deferredInitTask.promise.
|
|
896
897
|
then(function () {
|
|
897
898
|
// Check to see if this key is flagged as a safe eviction key and add it to the recentlyAccessedKeys list
|
|
898
|
-
if (isSafeEvictionKey(mapping.key)) {
|
|
899
|
-
|
|
900
|
-
|
|
899
|
+
if (!isSafeEvictionKey(mapping.key)) {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
901
902
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
// key must implement the canEvict property.
|
|
905
|
-
if (_underscore.default.isUndefined(mapping.canEvict)) {
|
|
906
|
-
throw new Error("Cannot subscribe to safe eviction key '" +
|
|
907
|
-
mapping.key + "' without providing a canEvict value.");
|
|
903
|
+
// Try to free some cache whenever we connect to a safe eviction key
|
|
904
|
+
_OnyxCache.default.removeLeastRecentlyUsedKeys();
|
|
908
905
|
|
|
909
|
-
|
|
906
|
+
if (mapping.withOnyxInstance && !isCollectionKey(mapping.key)) {
|
|
907
|
+
// All React components subscribing to a key flagged as a safe eviction
|
|
908
|
+
// key must implement the canEvict property.
|
|
909
|
+
if (_underscore.default.isUndefined(mapping.canEvict)) {
|
|
910
|
+
throw new Error("Cannot subscribe to safe eviction key '" +
|
|
911
|
+
mapping.key + "' without providing a canEvict value.");
|
|
910
912
|
|
|
911
|
-
addLastAccessedKey(mapping.key);
|
|
912
913
|
}
|
|
914
|
+
|
|
915
|
+
addLastAccessedKey(mapping.key);
|
|
913
916
|
}
|
|
914
917
|
}).
|
|
915
918
|
then(getAllKeys).
|
|
@@ -996,10 +999,10 @@ function remove(key) {
|
|
|
996
999
|
* @return {Promise}
|
|
997
1000
|
*/
|
|
998
1001
|
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];}
|
|
999
|
-
|
|
1002
|
+
Logger.logInfo("Handled error: " + error);
|
|
1000
1003
|
|
|
1001
1004
|
if (error && _str.default.startsWith(error.message, 'Failed to execute \'put\' on \'IDBObjectStore\'')) {
|
|
1002
|
-
|
|
1005
|
+
Logger.logAlert('Attempted to set invalid data set in Onyx. Please ensure all data is serializable.');
|
|
1003
1006
|
throw error;
|
|
1004
1007
|
}
|
|
1005
1008
|
|
|
@@ -1007,12 +1010,12 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
1007
1010
|
var keyForRemoval = _underscore.default.find(recentlyAccessedKeys, function (key) {return !evictionBlocklist[key];});
|
|
1008
1011
|
|
|
1009
1012
|
if (!keyForRemoval) {
|
|
1010
|
-
|
|
1013
|
+
Logger.logAlert('Out of storage. But found no acceptable keys to remove.');
|
|
1011
1014
|
throw error;
|
|
1012
1015
|
}
|
|
1013
1016
|
|
|
1014
1017
|
// Remove the least recently viewed key that is not currently being accessed and retry.
|
|
1015
|
-
|
|
1018
|
+
Logger.logInfo("Out of storage. Evicting least recently accessed key (" + keyForRemoval + ") and retrying.");
|
|
1016
1019
|
return remove(keyForRemoval).
|
|
1017
1020
|
then(function () {return onyxMethod.apply(void 0, args);});
|
|
1018
1021
|
}
|
|
@@ -1027,12 +1030,11 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
1027
1030
|
*/
|
|
1028
1031
|
function set(key, value) {
|
|
1029
1032
|
// Logging properties only since values could be sensitive things we don't want to log
|
|
1030
|
-
|
|
1033
|
+
Logger.logInfo("set() called for key: " + key + (_underscore.default.isObject(value) ? " properties: " + _underscore.default.keys(value).join(',') : ''));
|
|
1031
1034
|
|
|
1032
1035
|
// eslint-disable-next-line no-use-before-define
|
|
1033
1036
|
if (hasPendingMergeForKey(key)) {
|
|
1034
|
-
|
|
1035
|
-
(0, _Logger.logAlert)("Onyx.set() called after Onyx.merge() for key: " + key + ". It is recommended to use set() or merge() not both.");
|
|
1037
|
+
Logger.logAlert("Onyx.set() called after Onyx.merge() for key: " + key + ". It is recommended to use set() or merge() not both.");
|
|
1036
1038
|
}
|
|
1037
1039
|
|
|
1038
1040
|
// Adds the key to cache when it's not available
|
|
@@ -1171,7 +1173,7 @@ function merge(key, value) {
|
|
|
1171
1173
|
|
|
1172
1174
|
return set(key, modifiedData);
|
|
1173
1175
|
} catch (error) {
|
|
1174
|
-
|
|
1176
|
+
Logger.logAlert("An error occurred while applying merge for key: " + key + ", Error: " + error);
|
|
1175
1177
|
}
|
|
1176
1178
|
|
|
1177
1179
|
return Promise.resolve();
|
|
@@ -1228,10 +1230,11 @@ function clear() {
|
|
|
1228
1230
|
function mergeCollection(collectionKey, collection) {
|
|
1229
1231
|
// Confirm all the collection keys belong to the same parent
|
|
1230
1232
|
_underscore.default.each(collection, function (data, dataKey) {
|
|
1231
|
-
if (
|
|
1232
|
-
|
|
1233
|
-
throw new Error("Provided collection does not have all its data belonging to the same parent. CollectionKey: " + collectionKey + ", DataKey: " + dataKey);
|
|
1233
|
+
if (isKeyMatch(collectionKey, dataKey)) {
|
|
1234
|
+
return;
|
|
1234
1235
|
}
|
|
1236
|
+
|
|
1237
|
+
throw new Error("Provided collection doesn't have all its data belonging to the same parent. CollectionKey: " + collectionKey + ", DataKey: " + dataKey);
|
|
1235
1238
|
});
|
|
1236
1239
|
|
|
1237
1240
|
return getAllKeys().
|
|
@@ -1271,6 +1274,36 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1271
1274
|
});
|
|
1272
1275
|
}
|
|
1273
1276
|
|
|
1277
|
+
/**
|
|
1278
|
+
* Insert API responses and lifecycle data into Onyx
|
|
1279
|
+
*
|
|
1280
|
+
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge'), key: string, value: *}
|
|
1281
|
+
*/
|
|
1282
|
+
function update(data) {
|
|
1283
|
+
// First, validate the Onyx object is in the format we expect
|
|
1284
|
+
_underscore.default.each(data, function (_ref4) {var onyxMethod = _ref4.onyxMethod,key = _ref4.key;
|
|
1285
|
+
if (!_underscore.default.contains(['set', 'merge'], onyxMethod)) {
|
|
1286
|
+
throw new Error("Invalid onyxMethod " + onyxMethod + " in Onyx update.");
|
|
1287
|
+
}
|
|
1288
|
+
if (!_underscore.default.isString(key)) {
|
|
1289
|
+
throw new Error("Invalid " + typeof key + " key provided in Onyx update. Onyx key must be of type string.");
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
_underscore.default.each(data, function (_ref5) {var onyxMethod = _ref5.onyxMethod,key = _ref5.key,value = _ref5.value;
|
|
1294
|
+
switch (onyxMethod) {
|
|
1295
|
+
case 'set':
|
|
1296
|
+
set(key, value);
|
|
1297
|
+
break;
|
|
1298
|
+
case 'merge':
|
|
1299
|
+
merge(key, value);
|
|
1300
|
+
break;
|
|
1301
|
+
default:
|
|
1302
|
+
break;}
|
|
1303
|
+
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1274
1307
|
/**
|
|
1275
1308
|
* Initialize the store with actions and listening for storage events
|
|
1276
1309
|
*
|
|
@@ -1305,7 +1338,7 @@ function init()
|
|
|
1305
1338
|
|
|
1306
1339
|
|
|
1307
1340
|
|
|
1308
|
-
{var
|
|
1341
|
+
{var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},_ref6$keys = _ref6.keys,keys = _ref6$keys === void 0 ? {} : _ref6$keys,_ref6$initialKeyState = _ref6.initialKeyStates,initialKeyStates = _ref6$initialKeyState === void 0 ? {} : _ref6$initialKeyState,_ref6$safeEvictionKey = _ref6.safeEvictionKeys,safeEvictionKeys = _ref6$safeEvictionKey === void 0 ? [] : _ref6$safeEvictionKey,_ref6$maxCachedKeysCo = _ref6.maxCachedKeysCount,maxCachedKeysCount = _ref6$maxCachedKeysCo === void 0 ? 1000 : _ref6$maxCachedKeysCo,_ref6$captureMetrics = _ref6.captureMetrics,captureMetrics = _ref6$captureMetrics === void 0 ? false : _ref6$captureMetrics,_ref6$shouldSyncMulti = _ref6.shouldSyncMultipleInstances,shouldSyncMultipleInstances = _ref6$shouldSyncMulti === void 0 ? Boolean(__webpack_require__.g.localStorage) : _ref6$shouldSyncMulti,_ref6$keysToDisableSy = _ref6.keysToDisableSyncEvents,keysToDisableSyncEvents = _ref6$keysToDisableSy === void 0 ? [] : _ref6$keysToDisableSy;
|
|
1309
1342
|
if (captureMetrics) {
|
|
1310
1343
|
// The code here is only bundled and applied when the captureMetrics is set
|
|
1311
1344
|
// eslint-disable-next-line no-use-before-define
|
|
@@ -1347,9 +1380,10 @@ var Onyx = {
|
|
|
1347
1380
|
multiSet: multiSet,
|
|
1348
1381
|
merge: merge,
|
|
1349
1382
|
mergeCollection: mergeCollection,
|
|
1383
|
+
update: update,
|
|
1350
1384
|
clear: clear,
|
|
1351
1385
|
init: init,
|
|
1352
|
-
registerLogger:
|
|
1386
|
+
registerLogger: Logger.registerLogger,
|
|
1353
1387
|
addToEvictionBlockList: addToEvictionBlockList,
|
|
1354
1388
|
removeFromEvictionBlockList: removeFromEvictionBlockList,
|
|
1355
1389
|
isSafeEvictionKey: isSafeEvictionKey };
|
|
@@ -1374,14 +1408,18 @@ function applyDecorators() {
|
|
|
1374
1408
|
mergeCollection = decorate.decorateWithMetrics(mergeCollection, 'Onyx:mergeCollection');
|
|
1375
1409
|
getAllKeys = decorate.decorateWithMetrics(getAllKeys, 'Onyx:getAllKeys');
|
|
1376
1410
|
initializeWithDefaultKeyStates = decorate.decorateWithMetrics(initializeWithDefaultKeyStates, 'Onyx:defaults');
|
|
1411
|
+
update = decorate.decorateWithMetrics(update, 'Onyx:update');
|
|
1377
1412
|
/* eslint-enable */
|
|
1378
1413
|
|
|
1379
1414
|
// Re-expose decorated methods
|
|
1415
|
+
/* eslint-disable rulesdir/prefer-actions-set-data */
|
|
1380
1416
|
Onyx.set = set;
|
|
1381
1417
|
Onyx.multiSet = multiSet;
|
|
1382
1418
|
Onyx.clear = clear;
|
|
1383
1419
|
Onyx.merge = merge;
|
|
1384
1420
|
Onyx.mergeCollection = mergeCollection;
|
|
1421
|
+
Onyx.update = update;
|
|
1422
|
+
/* eslint-enable */
|
|
1385
1423
|
|
|
1386
1424
|
// Expose stats methods on Onyx
|
|
1387
1425
|
Onyx.getMetrics = decorate.getMetrics;
|
|
@@ -1402,7 +1440,6 @@ Onyx;exports["default"] = _default;
|
|
|
1402
1440
|
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");Object.defineProperty(exports, "__esModule", ({ value: true }));exports["default"] = void 0;var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js"));var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js"));var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js"));var _underscore = _interopRequireDefault(__webpack_require__(/*! underscore */ "underscore"));
|
|
1403
1441
|
var _merge = _interopRequireDefault(__webpack_require__(/*! lodash/merge */ "lodash/merge"));
|
|
1404
1442
|
|
|
1405
|
-
|
|
1406
1443
|
var isDefined = _underscore.default.negate(_underscore.default.isUndefined);
|
|
1407
1444
|
|
|
1408
1445
|
/**
|
|
@@ -1572,14 +1609,16 @@ OnyxCache = /*#__PURE__*/function () {
|
|
|
1572
1609
|
* Remove keys that don't fall into the range of recently used keys
|
|
1573
1610
|
*/ }, { key: "removeLeastRecentlyUsedKeys", value: function removeLeastRecentlyUsedKeys()
|
|
1574
1611
|
{
|
|
1575
|
-
if (this.recentKeys.size
|
|
1576
|
-
|
|
1577
|
-
var recentlyAccessed = (0, _toConsumableArray2.default)(this.recentKeys).slice(-this.maxRecentKeysSize);
|
|
1578
|
-
var storageKeys = _underscore.default.keys(this.storageMap);
|
|
1579
|
-
var keysToRemove = _underscore.default.difference(storageKeys, recentlyAccessed);
|
|
1580
|
-
|
|
1581
|
-
_underscore.default.each(keysToRemove, this.drop);
|
|
1612
|
+
if (this.recentKeys.size <= this.maxRecentKeysSize) {
|
|
1613
|
+
return;
|
|
1582
1614
|
}
|
|
1615
|
+
|
|
1616
|
+
// Get the last N keys by doing a negative slice
|
|
1617
|
+
var recentlyAccessed = (0, _toConsumableArray2.default)(this.recentKeys).slice(-this.maxRecentKeysSize);
|
|
1618
|
+
var storageKeys = _underscore.default.keys(this.storageMap);
|
|
1619
|
+
var keysToRemove = _underscore.default.difference(storageKeys, recentlyAccessed);
|
|
1620
|
+
|
|
1621
|
+
_underscore.default.each(keysToRemove, this.drop);
|
|
1583
1622
|
}
|
|
1584
1623
|
|
|
1585
1624
|
/**
|
|
@@ -1908,7 +1947,7 @@ var _react = _interopRequireDefault(__webpack_require__(/*! react */ "react"));
|
|
|
1908
1947
|
var _underscore = _interopRequireDefault(__webpack_require__(/*! underscore */ "underscore"));
|
|
1909
1948
|
var _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js"));
|
|
1910
1949
|
var _str = _interopRequireDefault(__webpack_require__(/*! expensify-common/lib/str */ "expensify-common/lib/str"));
|
|
1911
|
-
var _Onyx = _interopRequireDefault(__webpack_require__(/*! ./Onyx */ "./lib/Onyx.js"));var _jsxFileName = "/
|
|
1950
|
+
var _Onyx = _interopRequireDefault(__webpack_require__(/*! ./Onyx */ "./lib/Onyx.js"));var _jsxFileName = "/home/runner/work/react-native-onyx/react-native-onyx/lib/withOnyx.js";function _createSuper(Derived) {var hasNativeReflectConstruct = _isNativeReflectConstruct();return function _createSuperInternal() {var Super = (0, _getPrototypeOf2.default)(Derived),result;if (hasNativeReflectConstruct) {var NewTarget = (0, _getPrototypeOf2.default)(this).constructor;result = Reflect.construct(Super, arguments, NewTarget);} else {result = Super.apply(this, arguments);}return (0, _possibleConstructorReturn2.default)(this, result);};}function _isNativeReflectConstruct() {if (typeof Reflect === "undefined" || !Reflect.construct) return false;if (Reflect.construct.sham) return false;if (typeof Proxy === "function") return true;try {Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));return true;} catch (e) {return false;}}
|
|
1912
1951
|
|
|
1913
1952
|
/**
|
|
1914
1953
|
* Returns the display name of a component
|
|
@@ -2023,8 +2062,7 @@ function _default(mapOnyxToState) {var _this = this;
|
|
|
2023
2062
|
var key = _str.default.result(mapping.key, _this7.props);
|
|
2024
2063
|
|
|
2025
2064
|
if (!_Onyx.default.isSafeEvictionKey(key)) {
|
|
2026
|
-
|
|
2027
|
-
throw new Error("canEvict cannot be used on key '" + key + "'. This key must explicitly be flagged as safe for removal by adding it to Onyx.init({safeEvictionKeys: []}).");
|
|
2065
|
+
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: []}).");
|
|
2028
2066
|
}
|
|
2029
2067
|
|
|
2030
2068
|
if (canEvict) {
|
|
@@ -2048,6 +2086,7 @@ function _default(mapOnyxToState) {var _this = this;
|
|
|
2048
2086
|
mapping, statePropertyName) {
|
|
2049
2087
|
var key = _str.default.result(mapping.key, this.props);
|
|
2050
2088
|
|
|
2089
|
+
// eslint-disable-next-line rulesdir/prefer-onyx-connect-in-libs
|
|
2051
2090
|
this.activeConnectionIDs[key] = _Onyx.default.connect((0, _extends2.default)({},
|
|
2052
2091
|
mapping, {
|
|
2053
2092
|
key: key,
|