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

Possibility to log all state changes (not only actions or mutations) #1448

Closed
Danilo-Araujo-Silva opened this issue Nov 14, 2018 · 4 comments

Comments

@Danilo-Araujo-Silva
Copy link

What problem does this feature solve?

With these built-in logger plugin we are able to subscribe to our store and log all state mutations.

But, it looks like, for now, we are not able to log all state changes other than mutations or actions. What does it mean? For example, if we are controlling the state of the application drawer (like this one on the Vuetify project or more specifically some inline editing actions in the data table component) and we would like to connect (even mapping) the store state directly in the component we will not be able to log the mutations there, since there's no mutation action involved.

Maybe we could use events to try to accomplish that but I'll be far more difficult.

I think it could be very good for us we have the possibility to log state changes that are not triggered by mutations and actions too.

What does the proposed API look like?

const myPlugin = store => {
  // called when the store is initialized
  store.subscribe((state, mutation, action) => {
    // called after every state change and not only on mutations.
    // The mutation comes in the format of `{ type, payload }`.
  })
}
@leoyli
Copy link

leoyli commented Nov 14, 2018

In practice, you should never mutate states out of store (mutations). You’d either copy it into local state (e.g. form), or commit a mutation.

@jdoubleu
Copy link

The proposed API looks similar to #1440

@ktsn
Copy link
Member

ktsn commented Feb 13, 2019

You should not directly mutate state without mutations. That's one of the reason why we have mutation on Vuex - it allows us to notice the every state changes.

@ktsn ktsn closed this as completed Feb 13, 2019
@Danilo-Araujo-Silva
Copy link
Author

Well, I'm not really saying that we shouldn't use mutations to change the state. I was just trying to find a way to log all state changes because this could really help on development or in a debug process. But ok, this is not a problem for me anymore.

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

4 participants