Reading v2.0.0-rc.1 release notes we can see that getters should be available inside dynamically registered modules:
Nested Modules Improvements
Actions, getters and mutations are all supported inside modules.
But when looking in index.js source code, into dynamic module registration (module() method) I can see that getters are not propagated:
const {
state,
actions,
mutations,
modules
} = module
Dynamically registered module getters should be available.
http://www.webpackbin.com/E1JVbppL-
I define getters in two ways:
store.js using getters: {
rootState: (state) => state
} (when store initializes)widget.js using getters: {
moduleState : (state) => state
} (dynamic module registration, using store.module(...))As you can see in output this.$store.getters.moduleState is empty.
Tested in
Hello @karol-f ,
thanks for filing this issue.
I'm not sure what you think the issue is. You say you tested both versions. What was the expected result, and what was actually happening? Can you reprocude the problem e.g. on jsfiddle.net?
Because what you quoted from the release notes just means that you can _define_ getters (alongside actions etc) in modules and nested submodules, and that works perfectly well as far as I can tell.
Getters are also collected from all submodules and wrapped accordingly (so they are accessible through store.getters) - it just happens in different place than the one where you seemed to be looking, namely here:
const getters = extractModuleGetters(options.getters, modules)
But maybe I missunderstand what your issue is about - can you elaborate?
Hi @LinusBorg - sorry for not providing link with problematic code. Here it is:
http://www.webpackbin.com/E1JVbppL-
I define getters in two ways:
store.js using getters: {
rootState: (state) => state
} (when store initializes)widget.js using getters: {
moduleState : (state) => state
} (dynamic module registration, using store.module(...))As you can see in output this.$store.getters.moduleState is empty.
Sorry for confusion and not providing link in the first place, regards!
Okay, now I see the issue. Thanks for the demo, we will look into it.
@karol-f Could you edit your initial post to include the demo link?
@LinusBorg Done
The code to register the getters is just missing in store.module(...) as @karol-f points out.
store.module(...) needs something like the initStoreState(...) call that is used the constructor.
It's not missing, though - it'S in the wrong place.
When initializing the store, first getters are collected from all modules, then the module() method is called to recursively add state, actions and mutations from all modules.
So the code is there, it would have to be moved into module(), which is not a simple copy/paste job ;)
But we will get on it.
It's fixed on #253
Thanks @ktsn !!
Most helpful comment
It's not missing, though - it'S in the wrong place.
When initializing the store, first getters are collected from all modules, then the
module()method is called to recursively add state, actions and mutations from all modules.So the code is there, it would have to be moved into
module(), which is not a simple copy/paste job ;)But we will get on it.