react-native-onyx 1.0.49 → 1.0.51

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
@@ -1216,6 +1216,17 @@ 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
+ // When in memory only mode for certain keys we do not want to ever drop items from the cache as the user will have no way to recover them again via storage.
1227
+ cache.setRecentKeysLimit(Infinity);
1228
+ }
1229
+
1219
1230
  /**
1220
1231
  * Initialize the store with actions and listening for storage events
1221
1232
  *
@@ -1304,6 +1315,7 @@ const Onyx = {
1304
1315
  removeFromEvictionBlockList,
1305
1316
  isSafeEvictionKey,
1306
1317
  METHOD,
1318
+ setMemoryOnlyKeys,
1307
1319
  };
1308
1320
 
1309
1321
  /**
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",