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

Add a subscribeModule instance method #1503

Open
ianwalter opened this issue Feb 7, 2019 · 1 comment
Open

Add a subscribeModule instance method #1503

ianwalter opened this issue Feb 7, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@ianwalter
Copy link

ianwalter commented Feb 7, 2019

What problem does this feature solve?

Vuex doesn't provide a way for plugins to be notified when modules are added to the store dynamically through registerModule. This means that there can be changes in the state tree that are impossible for plugins to know about through the existing subscription methods like subscribe and subscribeAction. A common use case would be a plugin that saves the Vuex state to local storage. When a module is added through registerModule, the local storage plugin will not be able to store it's initial state to local storage.

What does the proposed API look like?

subscribeModule(handler: Function)

Subscribe to registerModule/unregisterModule events. The handler is called with a module object and a namespace when the module is registered. The module object is null when unregistered:

store.subscribeModule((mod, namespace) => {
  if (mod) {
    console.log(mod)
  } else {
    console.log(namespace)
  }
})
@ktsn ktsn added the proposal label Feb 13, 2019
@kiaking
Copy link
Member

kiaking commented Apr 23, 2020

Relates to #1193.

@kiaking kiaking added enhancement New feature or request and removed proposal labels Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants