react-native-onyx 1.0.48 → 1.0.50

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
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable no-continue */
2
- import _ from 'underscore';
3
- import Str from 'expensify-common/lib/str';
4
2
  import {deepEqual} from 'fast-equals';
5
3
  import lodashGet from 'lodash/get';
6
- import Storage from './storage';
4
+ import _ from 'underscore';
7
5
  import * as Logger from './Logger';
8
6
  import cache from './OnyxCache';
7
+ import * as Str from './Str';
9
8
  import createDeferredTask from './createDeferredTask';
10
9
  import fastMerge from './fastMerge';
11
10
  import * as PerformanceUtils from './metrics/PerformanceUtils';
11
+ import Storage from './storage';
12
12
 
13
13
  // Method constants
14
14
  const METHOD = {
@@ -1216,6 +1216,14 @@ function update(data) {
1216
1216
  return clearPromise.then(() => Promise.all(_.map(promises, p => p())));
1217
1217
  }
1218
1218
 
1219
+ /**
1220
+ * When set these keys will not be persisted to storage
1221
+ * @param {string[]} keyList
1222
+ */
1223
+ function setMemoryOnlyKeys(keyList) {
1224
+ Storage.setMemoryOnlyKeys(keyList);
1225
+ }
1226
+
1219
1227
  /**
1220
1228
  * Initialize the store with actions and listening for storage events
1221
1229
  *
@@ -1304,6 +1312,7 @@ const Onyx = {
1304
1312
  removeFromEvictionBlockList,
1305
1313
  isSafeEvictionKey,
1306
1314
  METHOD,
1315
+ setMemoryOnlyKeys,
1307
1316
  };
1308
1317
 
1309
1318
  /**
package/lib/Str.js ADDED
@@ -0,0 +1,29 @@
1
+ import _ from 'underscore';
2
+
3
+ /**
4
+ * Returns true if the haystack begins with the needle
5
+ *
6
+ * @param {String} haystack The full string to be searched
7
+ * @param {String} needle The case-sensitive string to search for
8
+ * @return {Boolean} Returns true if the haystack starts with the needle.
9
+ */
10
+ function startsWith(haystack, needle) {
11
+ return _.isString(haystack)
12
+ && _.isString(needle)
13
+ && haystack.startsWith(needle);
14
+ }
15
+
16
+ /**
17
+ * Checks if parameter is a string or function.
18
+ * If it is a string, then we will just return it.
19
+ * If it is a function, then we will call it with
20
+ * any additional arguments and return the result.
21
+ *
22
+ * @param {String|Function} parameter
23
+ * @returns {*}
24
+ */
25
+ function result(parameter, ...args) {
26
+ return _.isFunction(parameter) ? parameter(...args) : parameter;
27
+ }
28
+
29
+ export {startsWith, result};
@@ -8,6 +8,7 @@ import localforage from 'localforage';
8
8
  import _ from 'underscore';
9
9
  import {extendPrototype} from 'localforage-removeitems';
10
10
  import SyncQueue from '../../SyncQueue';
11
+ import * as Str from '../../Str';
11
12
  import fastMerge from '../../fastMerge';
12
13
 
13
14
  extendPrototype(localforage);
@@ -16,6 +17,11 @@ localforage.config({
16
17
  name: 'OnyxDB',
17
18
  });
18
19
 
20
+ /**
21
+ * Keys that will not ever be persisted to disk.
22
+ */
23
+ let memoryOnlyKeys = [];
24
+
19
25
  const provider = {
20
26
  /**
21
27
  * Writing very quickly to IndexedDB causes performance issues and can lock up the page and lead to jank.
@@ -23,6 +29,10 @@ const provider = {
23
29
  * to the next.
24
30
  */
25
31
  setItemQueue: new SyncQueue(({key, value, shouldMerge}) => {
32
+ if (_.find(memoryOnlyKeys, noCacheKey => Str.startsWith(key, noCacheKey))) {
33
+ return Promise.resolve();
34
+ }
35
+
26
36
  if (shouldMerge) {
27
37
  return localforage.getItem(key)
28
38
  .then((existingValue) => {
@@ -125,6 +135,13 @@ const provider = {
125
135
  setItem(key, value) {
126
136
  return this.setItemQueue.push({key, value});
127
137
  },
138
+
139
+ /**
140
+ * @param {string[]} keyList
141
+ */
142
+ setMemoryOnlyKeys(keyList) {
143
+ memoryOnlyKeys = keyList;
144
+ },
128
145
  };
129
146
 
130
147
  export default provider;
@@ -128,6 +128,11 @@ const provider = {
128
128
  * @returns {Promise<void>}
129
129
  */
130
130
  clear: () => db.executeAsync('DELETE FROM keyvaluepairs;', []),
131
+
132
+ /**
133
+ * Noop on mobile for now.
134
+ */
135
+ setMemoryOnlyKeys: () => {},
131
136
  };
132
137
 
133
138
  export default provider;
package/lib/withOnyx.js CHANGED
@@ -3,11 +3,11 @@
3
3
  * something in Onyx (a key/value store). That way, as soon as data in Onyx changes, the state will be set and the view
4
4
  * will automatically change to reflect the new data.
5
5
  */
6
+ import PropTypes from 'prop-types';
6
7
  import React from 'react';
7
8
  import _ from 'underscore';
8
- import PropTypes from 'prop-types';
9
- import Str from 'expensify-common/lib/str';
10
9
  import Onyx from './Onyx';
10
+ import * as Str from './Str';
11
11
 
12
12
  /**
13
13
  * Returns the display name of a component
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -58,7 +58,6 @@
58
58
  "eslint-config-expensify": "^2.0.24",
59
59
  "eslint-plugin-jsx-a11y": "^6.6.1",
60
60
  "eslint-plugin-react": "^7.31.10",
61
- "expensify-common": "git+https://github.com/Expensify/expensify-common.git#427295da130a4eacc184d38693664280d020dffd",
62
61
  "jest": "^26.5.2",
63
62
  "jest-cli": "^26.5.2",
64
63
  "jsdoc-to-markdown": "^7.1.0",
@@ -75,7 +74,6 @@
75
74
  "webpack-merge": "^5.8.0"
76
75
  },
77
76
  "peerDependencies": {
78
- "expensify-common": ">=1",
79
77
  "localforage": "^1.10.0",
80
78
  "localforage-removeitems": "^1.4.0",
81
79
  "react": ">=18.1.0",