One mutation might be commited by serveral actions, sometimes, I need the action's type which commited the mutation when writing a vuex plugin. For example:
A plugin that can maintain an state to monitor the asynchronous state of each action.
Without the provided action's type, the only way I can think of is that each action corresponds to a unique mutaion.
By the way, I know the subscribeAction method, but it can't help, because I need both mutation's type and action's type.
thx!
store.subscribe((mutation, state, type) => {
// mutation's type is 'mutation.type'
// action's type is 'type'
// I need these two types both.
})
Since mutations can be commited as Object-Style Commit you can pass any value, even if the mutation doesn't need it.
E.g.:
...
actions: {
MY_ACTION({ commit }, actionArgs) {
commit({
type: 'MY_MUTATION',
data: actionArgs,
$mySecretVar: true
})
}
...
Inside the store.subscribe method you can check for mutation.$mySecretVar.
Closing due to inactivity. I think you should just subscribe to action because it's possible now via subscribeAction method.
Most helpful comment
Since mutations can be commited as Object-Style Commit you can pass any value, even if the mutation doesn't need it.
E.g.:
Inside the
store.subscribemethod you can check formutation.$mySecretVar.