Skip to content

Commit e21119f

Browse files
committed
change: removed eslint suppressions, refactored for loops to for-of loops
1 parent c84e169 commit e21119f

4 files changed

Lines changed: 16 additions & 23 deletions

File tree

lib/OnyxCache.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,9 @@ class OnyxCache {
231231
numKeysToRemove--;
232232
}
233233

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

lib/OnyxUtils.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/prefer-for-of */
21
/* eslint-disable no-continue */
32
import {deepEqual} from 'fast-equals';
43
import lodashClone from 'lodash/clone';
@@ -664,8 +663,9 @@ function keysChanged<TKey extends CollectionKeyBase>(
664663
// 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().
665664
const stateMappingKeys = Object.keys(callbackToStateMapping);
666665
const collectionKeyLength = collectionKey.length;
667-
for (let i = 0; i < stateMappingKeys.length; i++) {
668-
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
666+
667+
for (const stateMappingKey of stateMappingKeys) {
668+
const subscriber = callbackToStateMapping[stateMappingKey];
669669
if (!subscriber) {
670670
continue;
671671
}
@@ -702,9 +702,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
702702
// If they are not using waitForCollectionCallback then we notify the subscriber with
703703
// the new merged data but only for any keys in the partial collection.
704704
const dataKeys = Object.keys(partialCollection ?? {});
705-
for (let j = 0; j < dataKeys.length; j++) {
706-
const dataKey = dataKeys[j];
707-
705+
for (const dataKey of dataKeys) {
708706
if (deepEqual(cachedCollection[dataKey], previousCollection[dataKey])) {
709707
continue;
710708
}
@@ -761,8 +759,7 @@ function keysChanged<TKey extends CollectionKeyBase>(
761759
const prevCollection = prevState?.[subscriber.statePropertyName] ?? {};
762760
const finalCollection = lodashClone(prevCollection);
763761
const dataKeys = Object.keys(partialCollection ?? {});
764-
for (let j = 0; j < dataKeys.length; j++) {
765-
const dataKey = dataKeys[j];
762+
for (const dataKey of dataKeys) {
766763
finalCollection[dataKey] = cachedCollection[dataKey];
767764
}
768765

@@ -881,8 +878,8 @@ function keyChanged<TKey extends OnyxKey>(
881878

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

884-
for (let i = 0; i < stateMappingKeys.length; i++) {
885-
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
881+
for (const stateMappingKey of stateMappingKeys) {
882+
const subscriber = callbackToStateMapping[stateMappingKey];
886883
if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
887884
continue;
888885
}
@@ -1346,7 +1343,7 @@ function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKe
13461343
// Performance improvement
13471344
// If the mapping is connected to an onyx key that is not a collection
13481345
// we can skip the call to getAllKeys() and return an array with a single item
1349-
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) {
1346+
if (!!mapping.key && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) {
13501347
return new Set([mapping.key]);
13511348
}
13521349
return getAllKeys();

lib/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @typescript-eslint/prefer-for-of */
2-
31
import type {ConnectOptions, OnyxInput, OnyxKey} from './types';
42

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

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

161158
if (Array.isArray(condition)) {
162159
shouldInclude = condition.includes(key);
163160
} else if (typeof condition === 'string') {
164161
shouldInclude = key === condition;
165162
} else {
166-
shouldInclude = condition(entries[i]);
163+
shouldInclude = condition([key, value]);
167164
}
168165

169166
if (include ? shouldInclude : !shouldInclude) {

tests/unit/subscribeToPropertiesTest.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ describe('Only the specific property changes when using withOnyx() and ', () =>
189189
return runAllAssertionsForCollection(TestComponentWithOnyx).then(() => {
190190
// Expect that the selector always gets called with the full object
191191
// from the onyx state, and not with the selector result value (string in this case).
192-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
193-
for (let i = 0; i < mockedSelector.mock.calls.length; i++) {
194-
const firstArg = mockedSelector.mock.calls[i][0];
192+
193+
for (const mockedCall of mockedSelector.mock.calls) {
194+
const firstArg = mockedCall[0];
195195
expect(firstArg).toBeDefined();
196196
expect(firstArg).toBeInstanceOf(Object);
197197
}

0 commit comments

Comments
 (0)