perf: remove extra spread operators from the combine maps function
This commit is contained in:
parent
634d010d92
commit
3686506f2a
@ -47,16 +47,29 @@ export function useAllLists(): AppState['lists']['byUrl'] {
|
|||||||
return useAppSelector((state) => state.lists.byUrl)
|
return useAppSelector((state) => state.lists.byUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return a proxy instead of doing a reduce
|
/**
|
||||||
|
* Combine the tokens in map2 with the tokens on map1, where tokens on map1 take precedence
|
||||||
|
* @param map1 the base token map
|
||||||
|
* @param map2 the map of additioanl tokens to add to the base map
|
||||||
|
*/
|
||||||
export function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
|
export function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
|
||||||
const chainIds = Object.keys({ ...map1, ...map2 }).map((id) => parseInt(id))
|
const chainIds = Object.keys(
|
||||||
return chainIds.reduce(
|
Object.keys(map1)
|
||||||
(acc, chainId) => ({
|
.concat(Object.keys(map2))
|
||||||
...acc,
|
.reduce<{ [chainId: string]: true }>((memo, value) => {
|
||||||
[chainId]: { ...map2[chainId], ...map1[chainId] },
|
memo[value] = true
|
||||||
}),
|
return memo
|
||||||
{}
|
}, {})
|
||||||
)
|
).map((id) => parseInt(id))
|
||||||
|
|
||||||
|
return chainIds.reduce<Mutable<TokenAddressMap>>((memo, chainId) => {
|
||||||
|
memo[chainId] = {
|
||||||
|
...map2[chainId],
|
||||||
|
// map1 takes precedence
|
||||||
|
...map1[chainId],
|
||||||
|
}
|
||||||
|
return memo
|
||||||
|
}, {}) as TokenAddressMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge tokens contained within lists from urls
|
// merge tokens contained within lists from urls
|
||||||
|
Loading…
Reference in New Issue
Block a user