react-native-onyx 1.0.104 → 1.0.106

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/README.md CHANGED
@@ -67,7 +67,7 @@ For `Array` the default behavior is to replace it fully, effectively making it e
67
67
 
68
68
  ```javascript
69
69
  Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Joe']); // -> ['Joe']
70
- Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Joe', 'Jack']
70
+ Onyx.merge(ONYXKEYS.EMPLOYEE_LIST, ['Jack']); // -> ['Jack']
71
71
  ```
72
72
 
73
73
  For `Object` values the default behavior uses `lodash/merge` under the hood to do a deep extend of the object.
@@ -1505,42 +1505,6 @@ function mergeCollection(collectionKey, collection) {
1505
1505
  });
1506
1506
  }
1507
1507
 
1508
- /**
1509
- * Internal recursive function to execute the functions in the correct order
1510
- *
1511
- * @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *}
1512
- * @returns {Promise<Void>}
1513
- */
1514
- function innerUpdate(data) {
1515
- if (data.length === 0) {
1516
- return Promise.resolve();
1517
- }
1518
-
1519
- const { onyxMethod, key, value } = data.shift();
1520
- let promise = Promise.resolve();
1521
- switch (onyxMethod) {
1522
- case METHOD.SET:
1523
- promise = set(key, value);
1524
- break;
1525
- case METHOD.MERGE:
1526
- promise = merge(key, value);
1527
- break;
1528
- case METHOD.MERGE_COLLECTION:
1529
- promise = mergeCollection(key, value);
1530
- break;
1531
- case METHOD.MULTI_SET:
1532
- promise = multiSet(value);
1533
- break;
1534
- case METHOD.CLEAR:
1535
- promise = clear();
1536
- break;
1537
- default:
1538
- break;}
1539
-
1540
-
1541
- return promise.then(() => innerUpdate(data));
1542
- }
1543
-
1544
1508
  /**
1545
1509
  * Insert API responses and lifecycle data into Onyx
1546
1510
  *
@@ -1549,9 +1513,8 @@ function innerUpdate(data) {
1549
1513
  */
1550
1514
  function update(data) {
1551
1515
  // First, validate the Onyx object is in the format we expect
1552
- const validMethods = [METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET];
1553
1516
  underscore__WEBPACK_IMPORTED_MODULE_1___default().each(data, (_ref3) => {let { onyxMethod, key, value } = _ref3;
1554
- if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().contains(validMethods, onyxMethod)) {
1517
+ if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET], onyxMethod)) {
1555
1518
  throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
1556
1519
  }
1557
1520
  if (onyxMethod === METHOD.MULTI_SET) {
@@ -1564,10 +1527,32 @@ function update(data) {
1564
1527
  }
1565
1528
  });
1566
1529
 
1567
- // Put clear operation on top
1568
- data.sort((a) => a.onyxMethod === METHOD.CLEAR ? -1 : 1);
1530
+ const promises = [];
1531
+ let clearPromise = Promise.resolve();
1532
+
1533
+ underscore__WEBPACK_IMPORTED_MODULE_1___default().each(data, (_ref4) => {let { onyxMethod, key, value } = _ref4;
1534
+ switch (onyxMethod) {
1535
+ case METHOD.SET:
1536
+ promises.push(() => set(key, value));
1537
+ break;
1538
+ case METHOD.MERGE:
1539
+ promises.push(() => merge(key, value));
1540
+ break;
1541
+ case METHOD.MERGE_COLLECTION:
1542
+ promises.push(() => mergeCollection(key, value));
1543
+ break;
1544
+ case METHOD.MULTI_SET:
1545
+ promises.push(() => multiSet(value));
1546
+ break;
1547
+ case METHOD.CLEAR:
1548
+ clearPromise = clear();
1549
+ break;
1550
+ default:
1551
+ break;}
1552
+
1553
+ });
1569
1554
 
1570
- return innerUpdate(data);
1555
+ return clearPromise.then(() => Promise.all(underscore__WEBPACK_IMPORTED_MODULE_1___default().map(promises, (p) => p())));
1571
1556
  }
1572
1557
 
1573
1558
  /**