Skip to content

Using an argument for computed filtering in signal store #4660

Discussion options

You must be logged in to vote

I mean withProps, if you don't want to put it into withMethods (for whatever reasons).

When you want to have a memoization process you could use it in withComputed() with nested computeds.

Kind of like this:

withComputed(state => ({
  userRights: computed(() => {
    const users = state.users();
    const rightCodes = state.rightCodes();
    return Object.fromEntries(users.map(user => [
      user.id,
      Object.fromEntries(rightCodes.map(rightCode => [rightCode, user.rights.includes(rightCode]))
    ]))
  })
}))

The access from the store would then be

const userId = 1
const rightRole = 'admin';

const hasRight = state.userRights()[userId]['admin']

I am not sure if I would do that. It i…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@rainerhahnekamp
Comment options

Answer selected by blackholegalaxy
@blackholegalaxy
Comment options

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