|
1 | | -/* eslint-disable @typescript-eslint/prefer-for-of */ |
2 | 1 | /* eslint-disable no-continue */ |
3 | 2 | import {deepEqual} from 'fast-equals'; |
4 | 3 | import lodashClone from 'lodash/clone'; |
@@ -666,8 +665,9 @@ function keysChanged<TKey extends CollectionKeyBase>( |
666 | 665 | // 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(). |
667 | 666 | const stateMappingKeys = Object.keys(callbackToStateMapping); |
668 | 667 | const collectionKeyLength = collectionKey.length; |
669 | | - for (let i = 0; i < stateMappingKeys.length; i++) { |
670 | | - const subscriber = callbackToStateMapping[stateMappingKeys[i]]; |
| 668 | + |
| 669 | + for (const stateMappingKey of stateMappingKeys) { |
| 670 | + const subscriber = callbackToStateMapping[stateMappingKey]; |
671 | 671 | if (!subscriber) { |
672 | 672 | continue; |
673 | 673 | } |
@@ -704,9 +704,7 @@ function keysChanged<TKey extends CollectionKeyBase>( |
704 | 704 | // If they are not using waitForCollectionCallback then we notify the subscriber with |
705 | 705 | // the new merged data but only for any keys in the partial collection. |
706 | 706 | const dataKeys = Object.keys(partialCollection ?? {}); |
707 | | - for (let j = 0; j < dataKeys.length; j++) { |
708 | | - const dataKey = dataKeys[j]; |
709 | | - |
| 707 | + for (const dataKey of dataKeys) { |
710 | 708 | if (deepEqual(cachedCollection[dataKey], previousCollection[dataKey])) { |
711 | 709 | continue; |
712 | 710 | } |
@@ -763,8 +761,7 @@ function keysChanged<TKey extends CollectionKeyBase>( |
763 | 761 | const prevCollection = prevState?.[subscriber.statePropertyName] ?? {}; |
764 | 762 | const finalCollection = lodashClone(prevCollection); |
765 | 763 | const dataKeys = Object.keys(partialCollection ?? {}); |
766 | | - for (let j = 0; j < dataKeys.length; j++) { |
767 | | - const dataKey = dataKeys[j]; |
| 764 | + for (const dataKey of dataKeys) { |
768 | 765 | finalCollection[dataKey] = cachedCollection[dataKey]; |
769 | 766 | } |
770 | 767 |
|
@@ -883,8 +880,8 @@ function keyChanged<TKey extends OnyxKey>( |
883 | 880 |
|
884 | 881 | const cachedCollections: Record<string, ReturnType<typeof getCachedCollection>> = {}; |
885 | 882 |
|
886 | | - for (let i = 0; i < stateMappingKeys.length; i++) { |
887 | | - const subscriber = callbackToStateMapping[stateMappingKeys[i]]; |
| 883 | + for (const stateMappingKey of stateMappingKeys) { |
| 884 | + const subscriber = callbackToStateMapping[stateMappingKey]; |
888 | 885 | if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) { |
889 | 886 | continue; |
890 | 887 | } |
@@ -1348,7 +1345,7 @@ function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKe |
1348 | 1345 | // Performance improvement |
1349 | 1346 | // If the mapping is connected to an onyx key that is not a collection |
1350 | 1347 | // we can skip the call to getAllKeys() and return an array with a single item |
1351 | | - if (Boolean(mapping.key) && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) { |
| 1348 | + if (!!mapping.key && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && cache.getAllKeys().has(mapping.key)) { |
1352 | 1349 | return new Set([mapping.key]); |
1353 | 1350 | } |
1354 | 1351 | return getAllKeys(); |
|
0 commit comments