react-native-onyx 1.0.25 → 1.0.27
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 +34 -11
- 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 +29 -10
- package/lib/OnyxCache.js +4 -0
- package/package.json +1 -1
package/dist/web.development.js
CHANGED
|
@@ -501,6 +501,14 @@ var _createDeferredTask = _interopRequireDefault(__webpack_require__(/*! ./creat
|
|
|
501
501
|
var _fastMerge = _interopRequireDefault(__webpack_require__(/*! ./fastMerge */ "./lib/fastMerge.js"));
|
|
502
502
|
var PerformanceUtils = _interopRequireWildcard(__webpack_require__(/*! ./metrics/PerformanceUtils */ "./lib/metrics/PerformanceUtils.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;} /* eslint-disable no-continue */
|
|
503
503
|
|
|
504
|
+
// Method constants
|
|
505
|
+
var METHOD = {
|
|
506
|
+
SET: 'set',
|
|
507
|
+
MERGE: 'merge',
|
|
508
|
+
MERGE_COLLECTION: 'mergecollection',
|
|
509
|
+
CLEAR: 'clear' };
|
|
510
|
+
|
|
511
|
+
|
|
504
512
|
// Keeps track of the last connectionID that was used so we can keep incrementing it
|
|
505
513
|
var lastConnectionID = 0;
|
|
506
514
|
|
|
@@ -1537,6 +1545,11 @@ function clear() {
|
|
|
1537
1545
|
* @returns {Promise}
|
|
1538
1546
|
*/
|
|
1539
1547
|
function mergeCollection(collectionKey, collection) {
|
|
1548
|
+
if (!_underscore.default.isObject(collection) || _underscore.default.isArray(collection) || _underscore.default.isEmpty(collection)) {
|
|
1549
|
+
Logger.logInfo('mergeCollection() called with invalid or empty value. Skipping this update.');
|
|
1550
|
+
return Promise.resolve();
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1540
1553
|
// Confirm all the collection keys belong to the same parent
|
|
1541
1554
|
_underscore.default.each(collection, function (_data, dataKey) {
|
|
1542
1555
|
if (isKeyMatch(collectionKey, dataKey)) {
|
|
@@ -1587,36 +1600,41 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1587
1600
|
* Insert API responses and lifecycle data into Onyx
|
|
1588
1601
|
*
|
|
1589
1602
|
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *}
|
|
1603
|
+
* @returns {Promise} resolves when all operations are complete
|
|
1590
1604
|
*/
|
|
1591
1605
|
function update(data) {
|
|
1592
1606
|
// First, validate the Onyx object is in the format we expect
|
|
1593
1607
|
_underscore.default.each(data, function (_ref9) {var onyxMethod = _ref9.onyxMethod,key = _ref9.key;
|
|
1594
|
-
if (!_underscore.default.contains([
|
|
1608
|
+
if (!_underscore.default.contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION], onyxMethod)) {
|
|
1595
1609
|
throw new Error("Invalid onyxMethod " + onyxMethod + " in Onyx update.");
|
|
1596
1610
|
}
|
|
1597
|
-
if (onyxMethod !==
|
|
1611
|
+
if (onyxMethod !== METHOD.CLEAR && !_underscore.default.isString(key)) {
|
|
1598
1612
|
throw new Error("Invalid " + typeof key + " key provided in Onyx update. Onyx key must be of type string.");
|
|
1599
1613
|
}
|
|
1600
1614
|
});
|
|
1601
1615
|
|
|
1616
|
+
var promises = [];
|
|
1617
|
+
|
|
1602
1618
|
_underscore.default.each(data, function (_ref10) {var onyxMethod = _ref10.onyxMethod,key = _ref10.key,value = _ref10.value;
|
|
1603
1619
|
switch (onyxMethod) {
|
|
1604
|
-
case
|
|
1605
|
-
set(key, value);
|
|
1620
|
+
case METHOD.SET:
|
|
1621
|
+
promises.push(set(key, value));
|
|
1606
1622
|
break;
|
|
1607
|
-
case
|
|
1608
|
-
merge(key, value);
|
|
1623
|
+
case METHOD.MERGE:
|
|
1624
|
+
promises.push(merge(key, value));
|
|
1609
1625
|
break;
|
|
1610
|
-
case
|
|
1611
|
-
mergeCollection(key, value);
|
|
1626
|
+
case METHOD.MERGE_COLLECTION:
|
|
1627
|
+
promises.push(mergeCollection(key, value));
|
|
1612
1628
|
break;
|
|
1613
|
-
case
|
|
1614
|
-
clear();
|
|
1629
|
+
case METHOD.CLEAR:
|
|
1630
|
+
promises.push(clear());
|
|
1615
1631
|
break;
|
|
1616
1632
|
default:
|
|
1617
1633
|
break;}
|
|
1618
1634
|
|
|
1619
1635
|
});
|
|
1636
|
+
|
|
1637
|
+
return Promise.all(promises);
|
|
1620
1638
|
}
|
|
1621
1639
|
|
|
1622
1640
|
/**
|
|
@@ -1704,7 +1722,8 @@ var Onyx = {
|
|
|
1704
1722
|
registerLogger: Logger.registerLogger,
|
|
1705
1723
|
addToEvictionBlockList: addToEvictionBlockList,
|
|
1706
1724
|
removeFromEvictionBlockList: removeFromEvictionBlockList,
|
|
1707
|
-
isSafeEvictionKey: isSafeEvictionKey
|
|
1725
|
+
isSafeEvictionKey: isSafeEvictionKey,
|
|
1726
|
+
METHOD: METHOD };
|
|
1708
1727
|
|
|
1709
1728
|
|
|
1710
1729
|
/**
|
|
@@ -1868,6 +1887,10 @@ OnyxCache = /*#__PURE__*/function () {
|
|
|
1868
1887
|
* @param {Record<string, *>} data - a map of (cache) key - values
|
|
1869
1888
|
*/ }, { key: "merge", value: function merge(
|
|
1870
1889
|
data) {var _this = this;
|
|
1890
|
+
if (!_underscore.default.isObject(data) || _underscore.default.isArray(data)) {
|
|
1891
|
+
throw new Error('data passed to cache.merge() must be an Object of onyx key/value pairs');
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1871
1894
|
// lodash adds a small overhead so we don't use it here
|
|
1872
1895
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
1873
1896
|
this.storageMap = (0, _extends2.default)({}, (0, _fastMerge.default)(this.storageMap, data));
|