Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Onyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function init({
initialKeyStates = {},
safeEvictionKeys = [],
maxCachedKeysCount = 1000,
shouldSyncMultipleInstances = Boolean(global.localStorage),
shouldSyncMultipleInstances = !!global.localStorage,
debugSetState = false,
enablePerformanceMetrics = false,
skippableCollectionMemberIDs = [],
Expand Down
7 changes: 3 additions & 4 deletions lib/OnyxCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ class OnyxCache {
numKeysToRemove--;
}

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < temp.length; ++i) {
delete this.storageMap[temp[i]];
this.recentKeys.delete(temp[i]);
for (const key of temp) {
delete this.storageMap[key];
this.recentKeys.delete(key);
}
}

Expand Down
19 changes: 8 additions & 11 deletions lib/OnyxUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/prefer-for-of */
/* eslint-disable no-continue */
import {deepEqual} from 'fast-equals';
import lodashClone from 'lodash/clone';
Expand Down Expand Up @@ -664,8 +663,9 @@ function keysChanged<TKey extends CollectionKeyBase>(
// and does not represent all of the combined keys and values for a collection key. It is just the "new" data that was merged in via mergeCollection().
const stateMappingKeys = Object.keys(callbackToStateMapping);
const collectionKeyLength = collectionKey.length;
for (let i = 0; i < stateMappingKeys.length; i++) {
const subscriber = callbackToStateMapping[stateMappingKeys[i]];

for (const stateMappingKey of stateMappingKeys) {
const subscriber = callbackToStateMapping[stateMappingKey];
if (!subscriber) {
continue;
}
Expand Down Expand Up @@ -702,9 +702,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
// If they are not using waitForCollectionCallback then we notify the subscriber with
// the new merged data but only for any keys in the partial collection.
const dataKeys = Object.keys(partialCollection ?? {});
for (let j = 0; j < dataKeys.length; j++) {
const dataKey = dataKeys[j];

for (const dataKey of dataKeys) {
if (deepEqual(cachedCollection[dataKey], previousCollection[dataKey])) {
continue;
}
Expand Down Expand Up @@ -761,8 +759,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
const prevCollection = prevState?.[subscriber.statePropertyName] ?? {};
const finalCollection = lodashClone(prevCollection);
const dataKeys = Object.keys(partialCollection ?? {});
for (let j = 0; j < dataKeys.length; j++) {
const dataKey = dataKeys[j];
for (const dataKey of dataKeys) {
finalCollection[dataKey] = cachedCollection[dataKey];
}

Expand Down Expand Up @@ -881,8 +878,8 @@ function keyChanged<TKey extends OnyxKey>(

const cachedCollections: Record<string, ReturnType<typeof getCachedCollection>> = {};

for (let i = 0; i < stateMappingKeys.length; i++) {
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
for (const stateMappingKey of stateMappingKeys) {
const subscriber = callbackToStateMapping[stateMappingKey];
if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
continue;
}
Expand Down Expand Up @@ -1346,7 +1343,7 @@ function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKe
// Performance improvement
// If the mapping is connected to an onyx key that is not a collection
// we can skip the call to getAllKeys() and return an array with a single item
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) {
if (!!mapping.key && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) {
return new Set([mapping.key]);
}
return getAllKeys();
Expand Down
7 changes: 2 additions & 5 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/prefer-for-of */

import type {ConnectOptions, OnyxInput, OnyxKey} from './types';

type EmptyObject = Record<string, never>;
Expand Down Expand Up @@ -154,16 +152,15 @@ function filterObject<TValue>(obj: Record<string, TValue>, condition: string | s
const result: Record<string, TValue> = {};
const entries = Object.entries(obj);

for (let i = 0; i < entries.length; i++) {
const [key, value] = entries[i];
for (const [key, value] of entries) {
let shouldInclude: boolean;

if (Array.isArray(condition)) {
shouldInclude = condition.includes(key);
} else if (typeof condition === 'string') {
shouldInclude = key === condition;
} else {
shouldInclude = condition(entries[i]);
shouldInclude = condition([key, value]);
}

if (include ? shouldInclude : !shouldInclude) {
Expand Down
Loading