react-native-onyx 1.0.64 → 1.0.65
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 +13 -4
- 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 +13 -4
- 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
|
|
|
@@ -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;
|