I have a vuex store with several modules, and I want to be able to listen to "global" dispatch
or commit
calls (aka actions and mutations) from within a module. For example, in an auth
module there are actions like login and logout. Whenever those actions are dispatched, I want another module ui
to also perform some action, like setting a language based on the logged in user.
I know I can just dispatch the ui
actions from within the login and logout actions in the auth
module. But I'd rather have it the other way around, so that ui
is listening to the events (actions and/or mutations) dispatched in auth
. This way I can easily create side effects without changing the "original" vuex module.
Maybe I need to use watches, but some actions don't alter state so I can't always use them. Creating a plugin is also an option, but I don't want to create an extra plugin each time I want to create such a side effect.
So my question; from within a vuex module, how can I listen to actions/mutations dispatched from other modules?