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/lib/Onyx.js
CHANGED
|
@@ -14,6 +14,7 @@ const METHOD = {
|
|
|
14
14
|
SET: 'set',
|
|
15
15
|
MERGE: 'merge',
|
|
16
16
|
MERGE_COLLECTION: 'mergecollection',
|
|
17
|
+
MULTI_SET: 'multiset',
|
|
17
18
|
CLEAR: 'clear',
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -26,8 +27,8 @@ let lastConnectionID = 0;
|
|
|
26
27
|
// Holds a mapping of all the react components that want their state subscribed to a store key
|
|
27
28
|
const callbackToStateMapping = {};
|
|
28
29
|
|
|
29
|
-
//
|
|
30
|
-
let
|
|
30
|
+
// Keeps a copy of the values of the onyx collection keys as a map for faster lookups
|
|
31
|
+
let onyxCollectionKeyMap = {};
|
|
31
32
|
|
|
32
33
|
// Holds a list of keys that have been directly subscribed to or recently modified from least to most recent
|
|
33
34
|
let recentlyAccessedKeys = [];
|
|
@@ -140,7 +141,7 @@ function getAllKeys() {
|
|
|
140
141
|
* @returns {Boolean}
|
|
141
142
|
*/
|
|
142
143
|
function isCollectionKey(key) {
|
|
143
|
-
return
|
|
144
|
+
return onyxCollectionKeyMap.has(key);
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
/**
|
|
@@ -1285,16 +1286,21 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1285
1286
|
/**
|
|
1286
1287
|
* Insert API responses and lifecycle data into Onyx
|
|
1287
1288
|
*
|
|
1288
|
-
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *}
|
|
1289
|
+
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *}
|
|
1289
1290
|
* @returns {Promise} resolves when all operations are complete
|
|
1290
1291
|
*/
|
|
1291
1292
|
function update(data) {
|
|
1292
1293
|
// First, validate the Onyx object is in the format we expect
|
|
1293
|
-
_.each(data, ({onyxMethod, key}) => {
|
|
1294
|
-
if (!_.contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION], onyxMethod)) {
|
|
1294
|
+
_.each(data, ({onyxMethod, key, value}) => {
|
|
1295
|
+
if (!_.contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET], onyxMethod)) {
|
|
1295
1296
|
throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
|
|
1296
1297
|
}
|
|
1297
|
-
if (onyxMethod
|
|
1298
|
+
if (onyxMethod === METHOD.MULTI_SET) {
|
|
1299
|
+
// For multiset, we just expect the value to be an object
|
|
1300
|
+
if (!_.isObject(value) || _.isArray(value) || _.isFunction(value)) {
|
|
1301
|
+
throw new Error('Invalid value provided in Onyx multiSet. Onyx multiSet value must be of type object.');
|
|
1302
|
+
}
|
|
1303
|
+
} else if (onyxMethod !== METHOD.CLEAR && !_.isString(key)) {
|
|
1298
1304
|
throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`);
|
|
1299
1305
|
}
|
|
1300
1306
|
});
|
|
@@ -1313,6 +1319,9 @@ function update(data) {
|
|
|
1313
1319
|
case METHOD.MERGE_COLLECTION:
|
|
1314
1320
|
promises.push(() => mergeCollection(key, value));
|
|
1315
1321
|
break;
|
|
1322
|
+
case METHOD.MULTI_SET:
|
|
1323
|
+
promises.push(() => multiSet(value));
|
|
1324
|
+
break;
|
|
1316
1325
|
case METHOD.CLEAR:
|
|
1317
1326
|
clearPromise = clear();
|
|
1318
1327
|
break;
|
|
@@ -1383,8 +1392,13 @@ function init({
|
|
|
1383
1392
|
cache.setRecentKeysLimit(maxCachedKeysCount);
|
|
1384
1393
|
}
|
|
1385
1394
|
|
|
1386
|
-
//
|
|
1387
|
-
|
|
1395
|
+
// We need the value of the collection keys later for checking if a
|
|
1396
|
+
// key is a collection. We store it in a map for faster lookup.
|
|
1397
|
+
const collectionValues = _.values(keys.COLLECTION);
|
|
1398
|
+
onyxCollectionKeyMap = _.reduce(collectionValues, (acc, val) => {
|
|
1399
|
+
acc.set(val, true);
|
|
1400
|
+
return acc;
|
|
1401
|
+
}, new Map());
|
|
1388
1402
|
|
|
1389
1403
|
// Set our default key states to use when initializing and clearing Onyx data
|
|
1390
1404
|
defaultKeyStates = initialKeyStates;
|