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.
@@ -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
 
@@ -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 !== METHOD.CLEAR && !underscore__WEBPACK_IMPORTED_MODULE_1___default().isString(key)) {
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;