react-native-onyx 2.0.20 → 2.0.21

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/dist/Onyx.js CHANGED
@@ -165,12 +165,12 @@ function get(key) {
165
165
  /**
166
166
  * Returns current key names stored in persisted storage
167
167
  * @private
168
- * @returns {Promise<string[]>}
168
+ * @returns {Promise<Set<Key>>}
169
169
  */
170
170
  function getAllKeys() {
171
171
  // When we've already read stored keys, resolve right away
172
172
  const storedKeys = OnyxCache_1.default.getAllKeys();
173
- if (storedKeys.length > 0) {
173
+ if (storedKeys.size > 0) {
174
174
  return Promise.resolve(storedKeys);
175
175
  }
176
176
  const taskName = 'getAllKeys';
@@ -181,7 +181,8 @@ function getAllKeys() {
181
181
  // Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
182
182
  const promise = storage_1.default.getAllKeys().then((keys) => {
183
183
  OnyxCache_1.default.setAllKeys(keys);
184
- return keys;
184
+ // return the updated set of keys
185
+ return OnyxCache_1.default.getAllKeys();
185
186
  });
186
187
  return OnyxCache_1.default.captureTask(taskName, promise);
187
188
  }
@@ -252,10 +253,16 @@ function tryGetCachedValue(key, mapping = {}) {
252
253
  const allCacheKeys = OnyxCache_1.default.getAllKeys();
253
254
  // It is possible we haven't loaded all keys yet so we do not know if the
254
255
  // collection actually exists.
255
- if (allCacheKeys.length === 0) {
256
+ if (allCacheKeys.size === 0) {
256
257
  return;
257
258
  }
258
- const matchingKeys = underscore_1.default.filter(allCacheKeys, (k) => k.startsWith(key));
259
+ const matchingKeys = [];
260
+ allCacheKeys.forEach((k) => {
261
+ if (!k.startsWith(key)) {
262
+ return;
263
+ }
264
+ matchingKeys.push(k);
265
+ });
259
266
  const values = underscore_1.default.reduce(matchingKeys, (finalObject, matchedKey) => {
260
267
  const cachedValue = OnyxCache_1.default.getValue(matchedKey);
261
268
  if (cachedValue) {
@@ -342,7 +349,7 @@ function addToEvictionBlockList(key, connectionID) {
342
349
  function addAllSafeEvictionKeysToRecentlyAccessedList() {
343
350
  return getAllKeys().then((keys) => {
344
351
  underscore_1.default.each(evictionAllowList, (safeEvictionKey) => {
345
- underscore_1.default.each(keys, (key) => {
352
+ keys.forEach((key) => {
346
353
  if (!isKeyMatch(safeEvictionKey, key)) {
347
354
  return;
348
355
  }
@@ -357,7 +364,13 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
357
364
  * @returns {Object}
358
365
  */
359
366
  function getCachedCollection(collectionKey) {
360
- const collectionMemberKeys = underscore_1.default.filter(OnyxCache_1.default.getAllKeys(), (storedKey) => isCollectionMemberKey(collectionKey, storedKey));
367
+ const collectionMemberKeys = [];
368
+ OnyxCache_1.default.getAllKeys().forEach((storedKey) => {
369
+ if (!isCollectionMemberKey(collectionKey, storedKey)) {
370
+ return;
371
+ }
372
+ collectionMemberKeys.push(storedKey);
373
+ });
361
374
  return underscore_1.default.reduce(collectionMemberKeys, (prev, curr) => {
362
375
  const cachedValue = OnyxCache_1.default.getValue(curr);
363
376
  if (!cachedValue) {
@@ -821,7 +834,13 @@ function connect(mapping) {
821
834
  // We search all the keys in storage to see if any are a "match" for the subscriber we are connecting so that we
822
835
  // can send data back to the subscriber. Note that multiple keys can match as a subscriber could either be
823
836
  // subscribed to a "collection key" or a single key.
824
- const matchingKeys = underscore_1.default.filter(keys, (key) => isKeyMatch(mapping.key, key));
837
+ const matchingKeys = [];
838
+ keys.forEach((key) => {
839
+ if (!isKeyMatch(mapping.key, key)) {
840
+ return;
841
+ }
842
+ matchingKeys.push(key);
843
+ });
825
844
  // If the key being connected to does not exist we initialize the value with null. For subscribers that connected
826
845
  // directly via connect() they will simply get a null value sent to them without any information about which key matched
827
846
  // since there are none matched. In withOnyx() we wait for all connected keys to return a value before rendering the child
@@ -1241,7 +1260,7 @@ function clear(keysToPreserve = []) {
1241
1260
  // status, or activeClients need to remain in Onyx even when signed out)
1242
1261
  // 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them
1243
1262
  // to null would cause unknown behavior)
1244
- underscore_1.default.each(keys, (key) => {
1263
+ keys.forEach((key) => {
1245
1264
  const isKeyToPreserve = underscore_1.default.contains(keysToPreserve, key);
1246
1265
  const isDefaultKey = underscore_1.default.has(defaultKeyStates, key);
1247
1266
  // If the key is being removed or reset to default:
@@ -1336,7 +1355,7 @@ function mergeCollection(collectionKey, collection) {
1336
1355
  return true;
1337
1356
  })
1338
1357
  .keys()
1339
- .partition((key) => persistedKeys.includes(key))
1358
+ .partition((key) => persistedKeys.has(key))
1340
1359
  .value();
1341
1360
  const existingKeyCollection = underscore_1.default.pick(collection, existingKeys);
1342
1361
  const newCollection = underscore_1.default.pick(collection, newKeys);
@@ -20,7 +20,7 @@ declare class OnyxCache {
20
20
  private maxRecentKeysSize;
21
21
  constructor();
22
22
  /** Get all the storage keys */
23
- getAllKeys(): Key[];
23
+ getAllKeys(): Set<Key>;
24
24
  /**
25
25
  * Get a cached value from storage
26
26
  * @param [shouldReindexCache] – This is an LRU cache, and by default accessing a value will make it become last in line to be evicted. This flag can be used to skip that and just access the value directly without side-effects.
package/dist/OnyxCache.js CHANGED
@@ -23,7 +23,7 @@ class OnyxCache {
23
23
  }
24
24
  /** Get all the storage keys */
25
25
  getAllKeys() {
26
- return Array.from(this.storageKeys);
26
+ return this.storageKeys;
27
27
  }
28
28
  /**
29
29
  * Get a cached value from storage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.20",
3
+ "version": "2.0.21",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",