Skip to content

How to attach derived properties in nested object in store? #228

Closed Answered by dai-shi
geocine asked this question in Q&A
Discussion options

You must be logged in to vote

Assuming you don't modify currentMenu reference, doesn't this work?

derive({
  totalPrice: (get) => {
    const currentMenu = get(state.currentMenu)
    return currentMenu.multiplier * currentMenu.items.reduce((p, c) => p + (c.selected ? c.price : 0), 0)
  },
}, {
  proxy: state,
})

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@geocine
Comment options

@dai-shi
Comment options

@geocine
Comment options

Answer selected by geocine
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