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/lib/Onyx.js CHANGED
@@ -8,7 +8,6 @@ import createDeferredTask from './createDeferredTask';
8
8
  import fastMerge from './fastMerge';
9
9
  import * as PerformanceUtils from './metrics/PerformanceUtils';
10
10
  import Storage from './storage';
11
- import DevTools from './DevTools';
12
11
 
13
12
  // Method constants
14
13
  const METHOD = {
@@ -38,11 +37,6 @@ let recentlyAccessedKeys = [];
38
37
  // whatever appears in this list it will NEVER be a candidate for eviction.
39
38
  let evictionAllowList = [];
40
39
 
41
- let devTools = {
42
- registerAction: () => {},
43
- clearState: () => {},
44
- };
45
-
46
40
  // Holds a map of keys and connectionID arrays whose keys will never be automatically evicted as
47
41
  // long as we have at least one subscriber that returns false for the canEvict property.
48
42
  const evictionBlocklist = {};
@@ -848,10 +842,7 @@ function notifyCollectionSubscribersOnNextTick(key, value) {
848
842
  function remove(key) {
849
843
  cache.drop(key);
850
844
  notifySubscribersOnNextTick(key, null);
851
- return Storage.removeItem(key).then((result) => {
852
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, undefined, {[key]: undefined});
853
- return result;
854
- });
845
+ return Storage.removeItem(key);
855
846
  }
856
847
 
857
848
  /**
@@ -975,7 +966,6 @@ function set(key, value) {
975
966
  const hasChanged = cache.hasValueChanged(key, valueWithNullRemoved);
976
967
 
977
968
  // This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
978
- broadcastUpdate(key, value, 'set');
979
969
  broadcastUpdate(key, valueWithNullRemoved, hasChanged, 'set');
980
970
 
981
971
  // If the value has not changed, calling Storage.setItem() would be redundant and a waste of performance, so return early instead.
@@ -984,10 +974,6 @@ function set(key, value) {
984
974
  }
985
975
 
986
976
  return Storage.setItem(key, valueWithNullRemoved)
987
- .then((result) => {
988
- devTools.registerAction(`SET/${key.toUpperCase()}`, valueWithNullRemoved, {[key]: valueWithNullRemoved});
989
- return result;
990
- })
991
977
  .catch(error => evictStorageAndRetry(error, set, key, valueWithNullRemoved));
992
978
  }
993
979
 
@@ -1018,11 +1004,6 @@ function multiSet(data) {
1018
1004
  // Update cache and optimistically inform subscribers on the next tick
1019
1005
  cache.set(key, val);
1020
1006
  notifySubscribersOnNextTick(key, val);
1021
- if (_.isNull(val)) {
1022
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, val, {[key]: undefined});
1023
- } else {
1024
- devTools.registerAction(`SET/${key.toUpperCase()}`, val, {[key]: val});
1025
- }
1026
1007
  });
1027
1008
 
1028
1009
  return Storage.multiSet(keyValuePairs)
@@ -1117,10 +1098,7 @@ function merge(key, changes) {
1117
1098
  return Promise.resolve();
1118
1099
  }
1119
1100
 
1120
- return Storage.mergeItem(key, batchedChanges, modifiedData).then((results) => {
1121
- devTools.registerAction(`MERGE/${key.toUpperCase()}`, modifiedData, {[key]: modifiedData});
1122
- return results;
1123
- });
1101
+ return Storage.mergeItem(key, batchedChanges, modifiedData);
1124
1102
  } catch (error) {
1125
1103
  Logger.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
1126
1104
  }
@@ -1132,10 +1110,9 @@ function merge(key, changes) {
1132
1110
  /**
1133
1111
  * Merge user provided default key value pairs.
1134
1112
  * @private
1135
- * @param {boolean} enableDevTools
1136
1113
  * @returns {Promise}
1137
1114
  */
1138
- function initializeWithDefaultKeyStates(enableDevTools = false) {
1115
+ function initializeWithDefaultKeyStates() {
1139
1116
  return Storage.multiGet(_.keys(defaultKeyStates))
1140
1117
  .then((pairs) => {
1141
1118
  const asObject = _.object(pairs);
@@ -1143,9 +1120,6 @@ function initializeWithDefaultKeyStates(enableDevTools = false) {
1143
1120
  const merged = fastMerge(asObject, defaultKeyStates);
1144
1121
  cache.merge(merged);
1145
1122
  _.each(merged, (val, key) => keyChanged(key, val));
1146
- if (enableDevTools) {
1147
- devTools = new DevTools(merged);
1148
- }
1149
1123
  });
1150
1124
  }
1151
1125
 
@@ -1193,7 +1167,7 @@ function clear(keysToPreserve = []) {
1193
1167
  // since collection key subscribers need to be updated differently
1194
1168
  if (!isKeyToPreserve) {
1195
1169
  const oldValue = cache.getValue(key);
1196
- const newValue = _.get(defaultKeyStates, key, undefined);
1170
+ const newValue = _.get(defaultKeyStates, key, null);
1197
1171
  if (newValue !== oldValue) {
1198
1172
  cache.set(key, newValue);
1199
1173
  const collectionKey = key.substring(0, key.indexOf('_') + 1);
@@ -1224,15 +1198,11 @@ function clear(keysToPreserve = []) {
1224
1198
  notifyCollectionSubscribersOnNextTick(key, value);
1225
1199
  });
1226
1200
 
1227
- const defaultKeyValueState = _.omit(defaultKeyStates, keysToPreserve);
1228
- const defaultKeyValuePairs = _.pairs(defaultKeyValueState);
1201
+ const defaultKeyValuePairs = _.pairs(_.omit(defaultKeyStates, keysToPreserve));
1229
1202
 
1230
1203
  // Remove only the items that we want cleared from storage, and reset others to default
1231
1204
  _.each(keysToBeClearedFromStorage, key => cache.drop(key));
1232
- return Storage.removeItems(keysToBeClearedFromStorage).then(() => {
1233
- devTools.clearState(keysToBeClearedFromStorage);
1234
- return Storage.multiSet(defaultKeyValuePairs);
1235
- });
1205
+ return Storage.removeItems(keysToBeClearedFromStorage).then(() => Storage.multiSet(defaultKeyValuePairs));
1236
1206
  });
1237
1207
  }
1238
1208
 
@@ -1306,11 +1276,6 @@ function mergeCollection(collectionKey, collection) {
1306
1276
  Promise.all(_.map(existingKeys, get)).then(() => {
1307
1277
  cache.merge(collection);
1308
1278
  keysChanged(collectionKey, collection);
1309
- if (_.isNull(collection)) {
1310
- devTools.registerAction(`REMOVE/${collectionKey.toUpperCase()}`, collection, {[collectionKey]: undefined});
1311
- } else {
1312
- devTools.registerAction(`SET/${collectionKey.toUpperCase()}`, collection, {[collectionKey]: collection});
1313
- }
1314
1279
  });
1315
1280
 
1316
1281
  return Promise.all(promises)
@@ -1412,7 +1377,6 @@ function init({
1412
1377
  captureMetrics = false,
1413
1378
  shouldSyncMultipleInstances = Boolean(global.localStorage),
1414
1379
  debugSetState = false,
1415
- enableDevTools = false,
1416
1380
  } = {}) {
1417
1381
  if (captureMetrics) {
1418
1382
  // The code here is only bundled and applied when the captureMetrics is set
@@ -1445,7 +1409,7 @@ function init({
1445
1409
  // Initialize all of our keys with data provided then give green light to any pending connections
1446
1410
  Promise.all([
1447
1411
  addAllSafeEvictionKeysToRecentlyAccessedList(),
1448
- initializeWithDefaultKeyStates(enableDevTools),
1412
+ initializeWithDefaultKeyStates(),
1449
1413
  ])
1450
1414
  .then(deferredInitTask.resolve);
1451
1415
 
@@ -1453,11 +1417,6 @@ function init({
1453
1417
  Storage.keepInstancesSync((key, value) => {
1454
1418
  cache.set(key, value);
1455
1419
  keyChanged(key, value);
1456
- if (_.isNull(value)) {
1457
- devTools.registerAction(`REMOVE/${key.toUpperCase()}`, value, {[key]: undefined});
1458
- } else {
1459
- devTools.registerAction(`SET/${key.toUpperCase()}`, value, {[key]: value});
1460
- }
1461
1420
  });
1462
1421
  }
1463
1422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.75",
3
+ "version": "1.0.77",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -71,7 +71,6 @@
71
71
  "react-native-performance": "^2.0.0",
72
72
  "react-native-quick-sqlite": "^8.0.0-beta.2",
73
73
  "react-test-renderer": "18.1.0",
74
- "remotedev": "^0.2.9",
75
74
  "type-fest": "^3.12.0",
76
75
  "webpack": "^5.72.1",
77
76
  "webpack-cli": "^4.9.2",
@@ -80,7 +79,7 @@
80
79
  "peerDependencies": {
81
80
  "idb-keyval": "^6.2.1",
82
81
  "react": ">=18.1.0",
83
- "react-native-performance": "^4.0.0",
82
+ "react-native-performance": "^5.1.0",
84
83
  "react-native-quick-sqlite": "^8.0.0-beta.2",
85
84
  "react-native-device-info": "^10.3.0"
86
85
  },
@@ -1 +0,0 @@
1
- /*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */
package/lib/DevTools.js DELETED
@@ -1,55 +0,0 @@
1
- import _ from 'underscore';
2
-
3
- const {connectViaExtension} = process.env.NODE_ENV === 'production' ? require('remotedev') : {
4
- connectViaExtension: () => ({
5
- init: () => {},
6
- send: () => {},
7
- }),
8
- };
9
-
10
- class DevTools {
11
- /**
12
- * @callback onStateChange
13
- * @param {object} state
14
- */
15
- /**
16
- * Creates an instance of DevTools, with an internal state that mirrors the storage.
17
- *
18
- * @param {object} initialState - initial state of the storage
19
- * @param {onStateChange} onStateChange - callback which is triggered when we timetravel to a different registered action
20
- */
21
- constructor(initialState = {}) {
22
- this.state = initialState;
23
- this.remotedev = connectViaExtension();
24
- this.remotedev.init(this.state);
25
- }
26
-
27
- /**
28
- * Registers an action that updated the current state of the storage
29
- *
30
- * @param {string} type - name of the action
31
- * @param {any} payload - data written to the storage
32
- * @param {object} stateChanges - partial state that got updated after the changes
33
- */
34
- registerAction(type, payload = undefined, stateChanges = {}) {
35
- const newState = {
36
- ...this.state,
37
- ...stateChanges,
38
- };
39
-
40
- this.remotedev.send({type, payload}, newState);
41
- this.state = newState;
42
- }
43
-
44
- /**
45
- * This clears the internal state of the DevTools, preserving the keys not included in `keyToBeRemoved`
46
- *
47
- * @param {string[]} keysToBeRemoved
48
- */
49
- clearState(keysToBeRemoved = []) {
50
- const pairs = _.map(keysToBeRemoved, key => [key, undefined]);
51
- this.registerAction('CLEAR', undefined, _.object(pairs));
52
- }
53
- }
54
-
55
- export default DevTools;