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

vuex@2.0 getters not registered within dynamic nested modules #248

Closed
karol-f opened this issue Jul 12, 2016 · 9 comments
Closed

vuex@2.0 getters not registered within dynamic nested modules #248

karol-f opened this issue Jul 12, 2016 · 9 comments
Labels
bug Something isn't working

Comments

@karol-f
Copy link

karol-f commented Jul 12, 2016

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

Desired behaviour

Dynamically registered module getters should be available.

Current behaviour

http://www.webpackbin.com/E1JVbppL-

I define getters in two ways:

  • in store.js using getters: { rootState: (state) => state } (when store initializes)
  • in 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

  • v2.0.0-rc.1
  • v2.0.0-rc.3
@karol-f karol-f changed the title vue@2.0 getters not registered with modules vue@2.0 getters not registered within modules Jul 12, 2016
@LinusBorg LinusBorg reopened this Jul 12, 2016
@LinusBorg
Copy link
Member

LinusBorg commented Jul 12, 2016

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?

@LinusBorg LinusBorg added the need repro Reproduction code is required label Jul 12, 2016
@karol-f
Copy link
Author

karol-f commented Jul 12, 2016

Hi @LinusBorg - sorry for not providing link with problematic code. Here it is:
http://www.webpackbin.com/E1JVbppL-

I define getters in two ways:

  • in store.js using getters: { rootState: (state) => state } (when store initializes)
  • in 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!

@karol-f karol-f changed the title vue@2.0 getters not registered within modules vue@2.0 getters not registered within nested modules Jul 12, 2016
@karol-f karol-f changed the title vue@2.0 getters not registered within nested modules vue@2.0 getters not registered within dynamic nested modules Jul 12, 2016
@karol-f karol-f changed the title vue@2.0 getters not registered within dynamic nested modules vuex@2.0 getters not registered within dynamic nested modules Jul 12, 2016
@LinusBorg
Copy link
Member

Okay, now I see the issue. Thanks for the demo, we will look into it.

@LinusBorg LinusBorg added bug Something isn't working and removed need repro Reproduction code is required labels Jul 12, 2016
@LinusBorg
Copy link
Member

@karol-f Could you edit your initial post to include the demo link?

@karol-f
Copy link
Author

karol-f commented Jul 12, 2016

@LinusBorg Done

@analog-nico
Copy link

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.

@LinusBorg
Copy link
Member

LinusBorg commented Jul 15, 2016

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.

@ktsn
Copy link
Member

ktsn commented Jul 22, 2016

It's fixed on #253

@LinusBorg
Copy link
Member

Thanks @ktsn !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants