Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
3686506f
Unverified
Commit
3686506f
authored
Jul 23, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: remove extra spread operators from the combine maps function
parent
634d010d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
hooks.ts
src/state/lists/hooks.ts
+22
-9
No files found.
src/state/lists/hooks.ts
View file @
3686506f
...
...
@@ -47,16 +47,29 @@ export function useAllLists(): AppState['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
{
const
chainIds
=
Object
.
keys
({
...
map1
,
...
map2
}).
map
((
id
)
=>
parseInt
(
id
))
return
chainIds
.
reduce
(
(
acc
,
chainId
)
=>
({
...
acc
,
[
chainId
]:
{
...
map2
[
chainId
],
...
map1
[
chainId
]
},
}),
{}
)
const
chainIds
=
Object
.
keys
(
Object
.
keys
(
map1
)
.
concat
(
Object
.
keys
(
map2
))
.
reduce
<
{
[
chainId
:
string
]:
true
}
>
((
memo
,
value
)
=>
{
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment