react-native-onyx 1.0.75 → 1.0.77

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/API.md CHANGED
@@ -319,7 +319,6 @@ Initialize the store with actions and listening for storage events
319
319
  | [options.captureMetrics] | <code>Boolean</code> | | Enables Onyx benchmarking and exposes the get/print/reset functions |
320
320
  | [options.shouldSyncMultipleInstances] | <code>Boolean</code> | | Auto synchronize storage events between multiple instances of Onyx running in different tabs/windows. Defaults to true for platforms that support local storage (web/desktop) |
321
321
  | [options.debugSetState] | <code>Boolean</code> | | Enables debugging setState() calls to connected components. |
322
- | [options.enableDevTools] | <code>Boolean</code> | | Enables debugging using Redux DevTools extension. |
323
322
 
324
323
  **Example**
325
324
  ```js
package/README.md CHANGED
@@ -321,18 +321,8 @@ Sample output of `Onyx.printMetrics()`
321
321
 
322
322
  # Debug mode
323
323
 
324
- ## Using debugSetState
325
-
326
324
  It can be useful to log why Onyx is calling `setState()` on a particular React component so that we can understand which key changed, what changed about the value, and the connected component that ultimately rendered as a result. When used correctly this can help isolate problem areas and unnecessary renders in the code. To enable this feature, pass `debugSetState: true` to the config and grep JS console logs for `[Onyx-Debug]`.
327
325
 
328
- ## Using Redux DevTools extension
329
-
330
- It can be useful to check the order of writes to the storage and it's state at a specific point in time.
331
-
332
- First, install Redux DevTools through your favorite browser ([Edge](https://microsoftedge.microsoft.com/addons/detail/redux-devtools/nnkgneoiohoecpdiaponcejilbhhikei), [Chrome](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd), [Firefox](https://addons.mozilla.org/en-US/firefox/addon/reduxdevtools/))
333
-
334
- Then, you can enable this type of debugging by passing `enableDevTools: true` to `Onyx.init({...})`.
335
-
336
326
  # Development
337
327
 
338
328
  `react-native` bundles source using the `metro` bundler. `metro` does not follow symlinks, so we can't use `npm link` to
@@ -11,77 +11,6 @@
11
11
  return /******/ (() => { // webpackBootstrap
12
12
  /******/ var __webpack_modules__ = ({
13
13
 
14
- /***/ "./lib/DevTools.js":
15
- /*!*************************!*\
16
- !*** ./lib/DevTools.js ***!
17
- \*************************/
18
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
19
-
20
- "use strict";
21
- __webpack_require__.r(__webpack_exports__);
22
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
24
- /* harmony export */ });
25
- /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "underscore");
26
- /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
27
-
28
-
29
- const { connectViaExtension } = false ? 0 : {
30
- connectViaExtension: () => ({
31
- init: () => {},
32
- send: () => {}
33
- })
34
- };
35
-
36
- class DevTools {
37
- /**
38
- * @callback onStateChange
39
- * @param {object} state
40
- */
41
- /**
42
- * Creates an instance of DevTools, with an internal state that mirrors the storage.
43
- *
44
- * @param {object} initialState - initial state of the storage
45
- * @param {onStateChange} onStateChange - callback which is triggered when we timetravel to a different registered action
46
- */
47
- constructor() {let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
- this.state = initialState;
49
- this.remotedev = connectViaExtension();
50
- this.remotedev.init(this.state);
51
- }
52
-
53
- /**
54
- * Registers an action that updated the current state of the storage
55
- *
56
- * @param {string} type - name of the action
57
- * @param {any} payload - data written to the storage
58
- * @param {object} stateChanges - partial state that got updated after the changes
59
- */
60
- registerAction(type) {let payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;let stateChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
61
- const newState = {
62
- ...this.state,
63
- ...stateChanges
64
- };
65
-
66
- this.remotedev.send({ type, payload }, newState);
67
- this.state = newState;
68
- }
69
-
70
- /**
71
- * This clears the internal state of the DevTools, preserving the keys not included in `keyToBeRemoved`
72
- *
73
- * @param {string[]} keysToBeRemoved
74
- */
75
- clearState() {let keysToBeRemoved = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
76
- const pairs = underscore__WEBPACK_IMPORTED_MODULE_0___default().map(keysToBeRemoved, (key) => [key, undefined]);
77
- this.registerAction('CLEAR', undefined, underscore__WEBPACK_IMPORTED_MODULE_0___default().object(pairs));
78
- }
79
- }
80
-
81
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (DevTools);
82
-
83
- /***/ }),
84
-
85
14
  /***/ "./lib/Logger.js":
86
15
  /*!***********************!*\
87
16
  !*** ./lib/Logger.js ***!
@@ -151,7 +80,6 @@ __webpack_require__.r(__webpack_exports__);
151
80
  /* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./fastMerge */ "./lib/fastMerge.js");
152
81
  /* harmony import */ var _metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./metrics/PerformanceUtils */ "./lib/metrics/PerformanceUtils.js");
153
82
  /* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./storage */ "./lib/storage/index.web.js");
154
- /* harmony import */ var _DevTools__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./DevTools */ "./lib/DevTools.js");
155
83
  /* eslint-disable no-continue */
156
84
 
157
85
 
@@ -163,7 +91,6 @@ __webpack_require__.r(__webpack_exports__);
163
91
 
164
92
 
165
93
 
166
-
167
94
  // Method constants
168
95
  const METHOD = {
169
96
  SET: 'set',
@@ -192,11 +119,6 @@ let recentlyAccessedKeys = [];
192
119
  // whatever appears in this list it will NEVER be a candidate for eviction.
193
120
  let evictionAllowList = [];
194
121
 
195
- let devTools = {
196
- registerAction: () => {},
197
- clearState: () => {}
198
- };
199
-
200
122
  // Holds a map of keys and connectionID arrays whose keys will never be automatically evicted as
201
123
  // long as we have at least one subscriber that returns false for the canEvict property.
202
124
  const evictionBlocklist = {};
@@ -1002,10 +924,7 @@ function notifyCollectionSubscribersOnNextTick(key, value) {
1002
924
  function remove(key) {
1003
925
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].drop(key);
1004
926
  notifySubscribersOnNextTick(key, null);
1005
- return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].removeItem(key).then((result) => {
1006
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, undefined, { [key]: undefined });
1007
- return result;
1008
- });
927
+ return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].removeItem(key);
1009
928
  }
1010
929
 
1011
930
  /**
@@ -1129,7 +1048,6 @@ function set(key, value) {
1129
1048
  const hasChanged = _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].hasValueChanged(key, valueWithNullRemoved);
1130
1049
 
1131
1050
  // This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
1132
- broadcastUpdate(key, value, 'set');
1133
1051
  broadcastUpdate(key, valueWithNullRemoved, hasChanged, 'set');
1134
1052
 
1135
1053
  // If the value has not changed, calling Storage.setItem() would be redundant and a waste of performance, so return early instead.
@@ -1138,10 +1056,6 @@ function set(key, value) {
1138
1056
  }
1139
1057
 
1140
1058
  return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].setItem(key, valueWithNullRemoved).
1141
- then((result) => {
1142
- devTools.registerAction(`SET/${key.toUpperCase()}`, valueWithNullRemoved, { [key]: valueWithNullRemoved });
1143
- return result;
1144
- }).
1145
1059
  catch((error) => evictStorageAndRetry(error, set, key, valueWithNullRemoved));
1146
1060
  }
1147
1061
 
@@ -1172,11 +1086,6 @@ function multiSet(data) {
1172
1086
  // Update cache and optimistically inform subscribers on the next tick
1173
1087
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].set(key, val);
1174
1088
  notifySubscribersOnNextTick(key, val);
1175
- if (underscore__WEBPACK_IMPORTED_MODULE_1___default().isNull(val)) {
1176
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, val, { [key]: undefined });
1177
- } else {
1178
- devTools.registerAction(`SET/${key.toUpperCase()}`, val, { [key]: val });
1179
- }
1180
1089
  });
1181
1090
 
1182
1091
  return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].multiSet(keyValuePairs).
@@ -1271,10 +1180,7 @@ function merge(key, changes) {
1271
1180
  return Promise.resolve();
1272
1181
  }
1273
1182
 
1274
- return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].mergeItem(key, batchedChanges, modifiedData).then((results) => {
1275
- devTools.registerAction(`MERGE/${key.toUpperCase()}`, modifiedData, { [key]: modifiedData });
1276
- return results;
1277
- });
1183
+ return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].mergeItem(key, batchedChanges, modifiedData);
1278
1184
  } catch (error) {
1279
1185
  _Logger__WEBPACK_IMPORTED_MODULE_5__.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
1280
1186
  }
@@ -1286,10 +1192,9 @@ function merge(key, changes) {
1286
1192
  /**
1287
1193
  * Merge user provided default key value pairs.
1288
1194
  * @private
1289
- * @param {boolean} enableDevTools
1290
1195
  * @returns {Promise}
1291
1196
  */
1292
- function initializeWithDefaultKeyStates() {let enableDevTools = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1197
+ function initializeWithDefaultKeyStates() {
1293
1198
  return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].multiGet(underscore__WEBPACK_IMPORTED_MODULE_1___default().keys(defaultKeyStates)).
1294
1199
  then((pairs) => {
1295
1200
  const asObject = underscore__WEBPACK_IMPORTED_MODULE_1___default().object(pairs);
@@ -1297,9 +1202,6 @@ function initializeWithDefaultKeyStates() {let enableDevTools = arguments.length
1297
1202
  const merged = (0,_fastMerge__WEBPACK_IMPORTED_MODULE_8__["default"])(asObject, defaultKeyStates);
1298
1203
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].merge(merged);
1299
1204
  underscore__WEBPACK_IMPORTED_MODULE_1___default().each(merged, (val, key) => keyChanged(key, val));
1300
- if (enableDevTools) {
1301
- devTools = new _DevTools__WEBPACK_IMPORTED_MODULE_9__["default"](merged);
1302
- }
1303
1205
  });
1304
1206
  }
1305
1207
 
@@ -1347,7 +1249,7 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
1347
1249
  // since collection key subscribers need to be updated differently
1348
1250
  if (!isKeyToPreserve) {
1349
1251
  const oldValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].getValue(key);
1350
- const newValue = underscore__WEBPACK_IMPORTED_MODULE_1___default().get(defaultKeyStates, key, undefined);
1252
+ const newValue = underscore__WEBPACK_IMPORTED_MODULE_1___default().get(defaultKeyStates, key, null);
1351
1253
  if (newValue !== oldValue) {
1352
1254
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].set(key, newValue);
1353
1255
  const collectionKey = key.substring(0, key.indexOf('_') + 1);
@@ -1378,15 +1280,11 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
1378
1280
  notifyCollectionSubscribersOnNextTick(key, value);
1379
1281
  });
1380
1282
 
1381
- const defaultKeyValueState = underscore__WEBPACK_IMPORTED_MODULE_1___default().omit(defaultKeyStates, keysToPreserve);
1382
- const defaultKeyValuePairs = underscore__WEBPACK_IMPORTED_MODULE_1___default().pairs(defaultKeyValueState);
1283
+ const defaultKeyValuePairs = underscore__WEBPACK_IMPORTED_MODULE_1___default().pairs(underscore__WEBPACK_IMPORTED_MODULE_1___default().omit(defaultKeyStates, keysToPreserve));
1383
1284
 
1384
1285
  // Remove only the items that we want cleared from storage, and reset others to default
1385
1286
  underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keysToBeClearedFromStorage, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].drop(key));
1386
- return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].removeItems(keysToBeClearedFromStorage).then(() => {
1387
- devTools.clearState(keysToBeClearedFromStorage);
1388
- return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].multiSet(defaultKeyValuePairs);
1389
- });
1287
+ return _storage__WEBPACK_IMPORTED_MODULE_4__["default"].removeItems(keysToBeClearedFromStorage).then(() => _storage__WEBPACK_IMPORTED_MODULE_4__["default"].multiSet(defaultKeyValuePairs));
1390
1288
  });
1391
1289
  }
1392
1290
 
@@ -1460,11 +1358,6 @@ function mergeCollection(collectionKey, collection) {
1460
1358
  Promise.all(underscore__WEBPACK_IMPORTED_MODULE_1___default().map(existingKeys, get)).then(() => {
1461
1359
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].merge(collection);
1462
1360
  keysChanged(collectionKey, collection);
1463
- if (underscore__WEBPACK_IMPORTED_MODULE_1___default().isNull(collection)) {
1464
- devTools.registerAction(`REMOVE/${collectionKey.toUpperCase()}`, collection, { [collectionKey]: undefined });
1465
- } else {
1466
- devTools.registerAction(`SET/${collectionKey.toUpperCase()}`, collection, { [collectionKey]: collection });
1467
- }
1468
1361
  });
1469
1362
 
1470
1363
  return Promise.all(promises).
@@ -1566,8 +1459,7 @@ function init()
1566
1459
 
1567
1460
 
1568
1461
 
1569
-
1570
- {let { keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCachedKeysCount = 1000, captureMetrics = false, shouldSyncMultipleInstances = Boolean(__webpack_require__.g.localStorage), debugSetState = false, enableDevTools = false } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1462
+ {let { keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCachedKeysCount = 1000, captureMetrics = false, shouldSyncMultipleInstances = Boolean(__webpack_require__.g.localStorage), debugSetState = false } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1571
1463
  if (captureMetrics) {
1572
1464
  // The code here is only bundled and applied when the captureMetrics is set
1573
1465
  // eslint-disable-next-line no-use-before-define
@@ -1599,7 +1491,7 @@ function init()
1599
1491
  // Initialize all of our keys with data provided then give green light to any pending connections
1600
1492
  Promise.all([
1601
1493
  addAllSafeEvictionKeysToRecentlyAccessedList(),
1602
- initializeWithDefaultKeyStates(enableDevTools)]).
1494
+ initializeWithDefaultKeyStates()]).
1603
1495
 
1604
1496
  then(deferredInitTask.resolve);
1605
1497
 
@@ -1607,11 +1499,6 @@ function init()
1607
1499
  _storage__WEBPACK_IMPORTED_MODULE_4__["default"].keepInstancesSync((key, value) => {
1608
1500
  _OnyxCache__WEBPACK_IMPORTED_MODULE_3__["default"].set(key, value);
1609
1501
  keyChanged(key, value);
1610
- if (underscore__WEBPACK_IMPORTED_MODULE_1___default().isNull(value)) {
1611
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, value, { [key]: undefined });
1612
- } else {
1613
- devTools.registerAction(`SET/${key.toUpperCase()}`, value, { [key]: value });
1614
- }
1615
1502
  });
1616
1503
  }
1617
1504
  }