-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Creating a new module via registerModule calling unrelated watches #524
Comments
Hi, thanks for reporting this issue. |
Currently when you register a new module, the store is considered reset. This will trigger all watchers that are watching the store state. |
Is this is something, that will be changed in a future version i.e will there be an option to stop a store reset on register. |
I maybe wrong but I noticed we can avoid this behavior. |
This issue still persist in v3.1.1. i have loaded one module dynamically using registerModule on a page. one of my parent component is watching other module state variable. so while registering module, watcher on unrelated module state is firing. same thing happening for unRegisterModule. @yyx990803 please have a look on this. |
Anyone has solution to ignore firing watchers on module registration or unregistration? |
any update regarding this issue ? |
@mojodev To prevent firing watchers when registering a new module, add a property with the name of the future module you wish to register in the main store with a
then :
|
To workaround this issue for dynamically created modules, when module name is known only at runtime - a nested store can be used: const nestedRoot = 'nestedRoot';
// register nested root
store.registerModule(nestedRoot, {
namespaced: true,
state: {},
});
const someDynamicName = 'someId';
// register nested modules, rootStore is not updated
sotre.registerModule([nestedRoot, someDynamicName], {
// dynamic module data
}); |
Not work on [email protected] |
Whenever I create a new module using registerModule an unrelated watcher is fired in the below component. The module created is not related to the existing scope module in anyway.
The text was updated successfully, but these errors were encountered: