Created
December 2, 2023 01:12
-
-
Save AlonsoK28/f614b9f3d8459feb98c96f782b738c82 to your computer and use it in GitHub Desktop.
ngRx | modify state of nested object-array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on(setMenuChildrenOpen, (state, { parentId, childrenId }) => { | |
const result = state.map(parent => { | |
if (parent.subAppId === parentId) { | |
if (parent.children && parent.children?.length) { | |
const chilResult = parent.children.map(child => { | |
if (child.subAppId === childrenId) { | |
return { | |
...child, | |
isAlreadyOpen: true | |
} | |
} else { | |
return parent; | |
} | |
}); | |
return { | |
...parent, | |
children: chilResult | |
} | |
} else { | |
return parent; | |
} | |
} else { | |
return parent; | |
} | |
}); | |
return result; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use the following example