Skip to content

Access store.getters in the watched getter function created for store.watch? #460

@dyreby

Description

@dyreby

Currently store.watch takes a getter function that receives store.state as its only argument. Would it be possible to also pass in the store.getters object as an argument to this newly created watched function?

The following would then be possible:

store.watch((state, getters) => {
  if (state.firstChoice) return getters.someComplicatedGetter
  else return getters.someOtherGetter
}, newValue => {
  console.log('callback:', newValue)
})

The reasoning is that one may want to watch for changes in a number of complicated getters defined and used elsewhere.

Thanks much for considering this idea.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions