Skip to content

EntityAdapter | removeMany with Predicate Function #2695

Answered by markerikson
xbaun asked this question in Q&A
Discussion options

You must be logged in to vote

Not directly, no.

The primary issue here is that functions are not serializable, and thus they don't belong in an action:

@ngrx/entity does actually have a removeMany(predicate) option, and RTK's createEntityAdapter started as a copy of that package. But, when we reworked the methods to be usable as reducers directly, we had to remove that method to keep usage consistent with Redux patterns.

The best option would be to do a .ids.filter(), look up the values from the .entities field, come up with an array of IDs to remove, and pass those to adapter.removeMany(state, ids).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xbaun
Comment options

Answer selected by xbaun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants