Using an argument for computed filtering in signal store #4660
-
Hi! Signal store is really great. I'm currently rewriting ngrx store selectors in computed. We used factory selectors to pass an argument to underlying selector like this was discussed on props deprecation documentation: export const hasRight = (rightCode: RightCode) => createSelector(selectUser, (user) => {
return user?.rights?.indexOf(rightCode) !== -1;
}); How that kind of things be achievable in signal store. withComputed((store) => ({
userById: (userId: string) => computed(() => store.users()[userId])
})), This produces an error:
My question may be dumb. I don't want to put all filtering logic in components. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
No, it is not dumb. In fact, a similar one was posted recently: #4651 So in your case, I'd put |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick answer here ! Putting in withMethods clearly work. Will it still preserve kind of a "memoization" process? |
Beta Was this translation helpful? Give feedback.
I mean
withProps
, if you don't want to put it intowithMethods
(for whatever reasons).When you want to have a memoization process you could use it in
withComputed()
with nested computeds.Kind of like this:
The access from the store would then be
I am not sure if I would do that. It i…