Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide action's type in store.subscribe #1440

Closed
fxxjdedd opened this issue Nov 5, 2018 · 2 comments
Closed

Provide action's type in store.subscribe #1440

fxxjdedd opened this issue Nov 5, 2018 · 2 comments

Comments

@fxxjdedd
Copy link

fxxjdedd commented Nov 5, 2018

What problem does this feature solve?

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!

What does the proposed API look like?

store.subscribe((mutation,  state,  type) => {
  // mutation's type is 'mutation.type'
  // action's type is 'type'

  // I need these two types both.
})
@jdoubleu
Copy link

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.

@kiaking
Copy link
Member

kiaking commented Apr 23, 2020

Closing due to inactivity. I think you should just subscribe to action because it's possible now via subscribeAction method.

@kiaking kiaking closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants