react-native-onyx 1.0.64 → 1.0.66
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 +23 -9
- 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 +23 -9
- package/package.json +1 -1
package/dist/web.development.js
CHANGED
|
@@ -96,6 +96,7 @@ const METHOD = {
|
|
|
96
96
|
SET: 'set',
|
|
97
97
|
MERGE: 'merge',
|
|
98
98
|
MERGE_COLLECTION: 'mergecollection',
|
|
99
|
+
MULTI_SET: 'multiset',
|
|
99
100
|
CLEAR: 'clear'
|
|
100
101
|
};
|
|
101
102
|
|
|
@@ -108,8 +109,8 @@ let lastConnectionID = 0;
|
|
|
108
109
|
// Holds a mapping of all the react components that want their state subscribed to a store key
|
|
109
110
|
const callbackToStateMapping = {};
|
|
110
111
|
|
|
111
|
-
//
|
|
112
|
-
let
|
|
112
|
+
// Keeps a copy of the values of the onyx collection keys as a map for faster lookups
|
|
113
|
+
let onyxCollectionKeyMap = {};
|
|
113
114
|
|
|
114
115
|
// Holds a list of keys that have been directly subscribed to or recently modified from least to most recent
|
|
115
116
|
let recentlyAccessedKeys = [];
|
|
@@ -222,7 +223,7 @@ function getAllKeys() {
|
|
|
222
223
|
* @returns {Boolean}
|
|
223
224
|
*/
|
|
224
225
|
function isCollectionKey(key) {
|
|
225
|
-
return
|
|
226
|
+
return onyxCollectionKeyMap.has(key);
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
/**
|
|
@@ -1367,16 +1368,21 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1367
1368
|
/**
|
|
1368
1369
|
* Insert API responses and lifecycle data into Onyx
|
|
1369
1370
|
*
|
|
1370
|
-
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *}
|
|
1371
|
+
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *}
|
|
1371
1372
|
* @returns {Promise} resolves when all operations are complete
|
|
1372
1373
|
*/
|
|
1373
1374
|
function update(data) {
|
|
1374
1375
|
// First, validate the Onyx object is in the format we expect
|
|
1375
|
-
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(data, (_ref2) => {let { onyxMethod, key } = _ref2;
|
|
1376
|
-
if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION], onyxMethod)) {
|
|
1376
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(data, (_ref2) => {let { onyxMethod, key, value } = _ref2;
|
|
1377
|
+
if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET], onyxMethod)) {
|
|
1377
1378
|
throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
|
|
1378
1379
|
}
|
|
1379
|
-
if (onyxMethod
|
|
1380
|
+
if (onyxMethod === METHOD.MULTI_SET) {
|
|
1381
|
+
// For multiset, we just expect the value to be an object
|
|
1382
|
+
if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(value) || underscore__WEBPACK_IMPORTED_MODULE_1___default().isArray(value) || underscore__WEBPACK_IMPORTED_MODULE_1___default().isFunction(value)) {
|
|
1383
|
+
throw new Error('Invalid value provided in Onyx multiSet. Onyx multiSet value must be of type object.');
|
|
1384
|
+
}
|
|
1385
|
+
} else if (onyxMethod !== METHOD.CLEAR && !underscore__WEBPACK_IMPORTED_MODULE_1___default().isString(key)) {
|
|
1380
1386
|
throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`);
|
|
1381
1387
|
}
|
|
1382
1388
|
});
|
|
@@ -1395,6 +1401,9 @@ function update(data) {
|
|
|
1395
1401
|
case METHOD.MERGE_COLLECTION:
|
|
1396
1402
|
promises.push(() => mergeCollection(key, value));
|
|
1397
1403
|
break;
|
|
1404
|
+
case METHOD.MULTI_SET:
|
|
1405
|
+
promises.push(() => multiSet(value));
|
|
1406
|
+
break;
|
|
1398
1407
|
case METHOD.CLEAR:
|
|
1399
1408
|
clearPromise = clear();
|
|
1400
1409
|
break;
|
|
@@ -1465,8 +1474,13 @@ function init()
|
|
|
1465
1474
|
_OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].setRecentKeysLimit(maxCachedKeysCount);
|
|
1466
1475
|
}
|
|
1467
1476
|
|
|
1468
|
-
//
|
|
1469
|
-
|
|
1477
|
+
// We need the value of the collection keys later for checking if a
|
|
1478
|
+
// key is a collection. We store it in a map for faster lookup.
|
|
1479
|
+
const collectionValues = underscore__WEBPACK_IMPORTED_MODULE_1___default().values(keys.COLLECTION);
|
|
1480
|
+
onyxCollectionKeyMap = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(collectionValues, (acc, val) => {
|
|
1481
|
+
acc.set(val, true);
|
|
1482
|
+
return acc;
|
|
1483
|
+
}, new Map());
|
|
1470
1484
|
|
|
1471
1485
|
// Set our default key states to use when initializing and clearing Onyx data
|
|
1472
1486
|
defaultKeyStates = initialKeyStates;
|