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/lib/Onyx.js CHANGED
@@ -1422,42 +1422,6 @@ function mergeCollection(collectionKey, collection) {
1422
1422
  });
1423
1423
  }
1424
1424
 
1425
- /**
1426
- * Internal recursive function to execute the functions in the correct order
1427
- *
1428
- * @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *}
1429
- * @returns {Promise<Void>}
1430
- */
1431
- function innerUpdate(data) {
1432
- if (data.length === 0) {
1433
- return Promise.resolve();
1434
- }
1435
-
1436
- const {onyxMethod, key, value} = data.shift();
1437
- let promise = Promise.resolve();
1438
- switch (onyxMethod) {
1439
- case METHOD.SET:
1440
- promise = set(key, value);
1441
- break;
1442
- case METHOD.MERGE:
1443
- promise = merge(key, value);
1444
- break;
1445
- case METHOD.MERGE_COLLECTION:
1446
- promise = mergeCollection(key, value);
1447
- break;
1448
- case METHOD.MULTI_SET:
1449
- promise = multiSet(value);
1450
- break;
1451
- case METHOD.CLEAR:
1452
- promise = clear();
1453
- break;
1454
- default:
1455
- break;
1456
- }
1457
-
1458
- return promise.then(() => innerUpdate(data));
1459
- }
1460
-
1461
1425
  /**
1462
1426
  * Insert API responses and lifecycle data into Onyx
1463
1427
  *
@@ -1466,9 +1430,8 @@ function innerUpdate(data) {
1466
1430
  */
1467
1431
  function update(data) {
1468
1432
  // First, validate the Onyx object is in the format we expect
1469
- const validMethods = [METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET];
1470
1433
  _.each(data, ({onyxMethod, key, value}) => {
1471
- if (!_.contains(validMethods, onyxMethod)) {
1434
+ if (!_.contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION, METHOD.MULTI_SET], onyxMethod)) {
1472
1435
  throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
1473
1436
  }
1474
1437
  if (onyxMethod === METHOD.MULTI_SET) {
@@ -1481,10 +1444,32 @@ function update(data) {
1481
1444
  }
1482
1445
  });
1483
1446
 
1484
- // Put clear operation on top
1485
- data.sort(a => (a.onyxMethod === METHOD.CLEAR ? -1 : 1));
1447
+ const promises = [];
1448
+ let clearPromise = Promise.resolve();
1449
+
1450
+ _.each(data, ({onyxMethod, key, value}) => {
1451
+ switch (onyxMethod) {
1452
+ case METHOD.SET:
1453
+ promises.push(() => set(key, value));
1454
+ break;
1455
+ case METHOD.MERGE:
1456
+ promises.push(() => merge(key, value));
1457
+ break;
1458
+ case METHOD.MERGE_COLLECTION:
1459
+ promises.push(() => mergeCollection(key, value));
1460
+ break;
1461
+ case METHOD.MULTI_SET:
1462
+ promises.push(() => multiSet(value));
1463
+ break;
1464
+ case METHOD.CLEAR:
1465
+ clearPromise = clear();
1466
+ break;
1467
+ default:
1468
+ break;
1469
+ }
1470
+ });
1486
1471
 
1487
- return innerUpdate(data);
1472
+ return clearPromise.then(() => Promise.all(_.map(promises, p => p())));
1488
1473
  }
1489
1474
 
1490
1475
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.104",
3
+ "version": "1.0.106",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",