react-native-onyx 1.0.28 → 1.0.30

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
@@ -335,6 +335,6 @@ To quickly test small changes you can directly go to `node_modules/react-native-
335
335
  To continuously work on Onyx we have to set up a task that copies content to parent project's `node_modules/react-native-onyx`:
336
336
  1. Work on Onyx feature or a fix
337
337
  2. Save files
338
- 3. Optional: run `npm build` (if you're working or want to test on a non react-native project)
338
+ 3. Optional: run `npm run build` (if you're working or want to test on a non react-native project)
339
339
  - `npm link` would actually work outside of `react-native` and it can be used to link Onyx locally for a web only project
340
340
  4. Copy Onyx to consumer project's `node_modules/react-native-onyx`
@@ -1152,7 +1152,10 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
1152
1152
  * @param {Boolean} [mapping.initWithStoredValues] If set to false, then no data will be prefilled into the
1153
1153
  * component
1154
1154
  * @param {Boolean} [mapping.waitForCollectionCallback] If set to true, it will return the entire collection to the callback as a single object
1155
- * @param {String|Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData is passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint).
1155
+ * @param {String|Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data.
1156
+ * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData is passed to the selector and should return the
1157
+ * simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes.
1158
+ * Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint).
1156
1159
  * @returns {Number} an ID to use when calling disconnect
1157
1160
  */
1158
1161
  function connect(mapping) {
@@ -1516,17 +1519,37 @@ function initializeWithDefaultKeyStates() {
1516
1519
  * Storage.setItem() from Onyx.clear() will have already finished and the merged
1517
1520
  * value will be saved to storage after the default value.
1518
1521
  *
1522
+ * @param {Array} keysToPreserve is a list of ONYXKEYS that should not be cleared with the rest of the data
1519
1523
  * @returns {Promise<void>}
1520
1524
  */
1521
- function clear() {
1525
+ function clear() {var keysToPreserve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1522
1526
  return getAllKeys().
1523
1527
  then(function (keys) {
1524
- _underscore.default.each(keys, function (key) {
1525
- var resetValue = (0, _get.default)(defaultKeyStates, key, null);
1526
- _OnyxCache.default.set(key, resetValue);
1527
- notifySubscribersOnNextTick(key, resetValue);
1528
+ var keyValuesToReset = [];
1529
+ var defaultKeys = _underscore.default.keys(defaultKeyStates);
1530
+
1531
+ // The only keys that should not be cleared are:
1532
+ // 1. Anything specifically passed in keysToPreserve (because some keys like language preferences, offline status, or activeClients need to remain in Onyx even when signed out)
1533
+ // 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them to null would cause unknown behavior)
1534
+ var keysToClear = _underscore.default.difference(keys, keysToPreserve, defaultKeys);
1535
+ keyValuesToReset.push.apply(keyValuesToReset, (0, _toConsumableArray2.default)(_underscore.default.map(keysToClear, function (key) {return [key, null];})));
1536
+
1537
+ // Remove any keysToPreserve from the defaultKeyStates because if they are passed in it has been explicitly called out to preserve those values instead of resetting them back
1538
+ // to the default.
1539
+ var defaultKeyValuePairs = _underscore.default.pairs(_underscore.default.omit.apply(_underscore.default, [defaultKeyStates].concat((0, _toConsumableArray2.default)(keysToPreserve))));
1540
+
1541
+ // Add the default key value pairs to the keyValuesToReset so that they get set back to their default values when we clear Onyx
1542
+ keyValuesToReset.push.apply(keyValuesToReset, (0, _toConsumableArray2.default)(defaultKeyValuePairs));
1543
+
1544
+ // Make sure that we also reset the cache values before clearing the values from storage.
1545
+ // We do this before clearing Storage so that any call to clear() followed by merge() on a key with a default state results in the merged value getting saved, since the update
1546
+ // from the merge() call would happen on the tick after the update from this clear()
1547
+ _underscore.default.each(keyValuesToReset, function (keyValue) {
1548
+ _OnyxCache.default.set(keyValue[0], keyValue[1]);
1549
+ notifySubscribersOnNextTick(keyValue[0], keyValue[1]);
1528
1550
  });
1529
- return _storage.default.clear();
1551
+
1552
+ return _storage.default.multiSet(keyValuesToReset);
1530
1553
  });
1531
1554
  }
1532
1555
 
@@ -2228,7 +2251,7 @@ function logSetStateCall(mapping, previousValue, newValue, caller, keyThatChange
2228
2251
 
2229
2252
  Object.defineProperty(exports, "__esModule", ({ value: true }));exports.decorateWithMetrics = decorateWithMetrics;exports.getMetrics = getMetrics;exports.resetMetrics = resetMetrics;exports.printMetrics = printMetrics; // For web-only implementations of Onyx, this module will just be a no-op
2230
2253
 
2231
- function decorateWithMetrics() {}
2254
+ function decorateWithMetrics(func) {return func;}
2232
2255
  function getMetrics() {}
2233
2256
  function printMetrics() {}
2234
2257
  function resetMetrics() {}