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 ability to access namespaced getters with dot notation #1258

Open
jmcooper opened this Issue May 5, 2018 · 4 comments

Comments

Projects
None yet
5 participants
@jmcooper
Copy link

jmcooper commented May 5, 2018

What problem does this feature solve?

When working with a namespaced module (e.g. a users module), you can access items on the user module's state like this:
this.$store.state.users.user

However, you can't access getters in the same way. This will return an error:
this.$store.getters.users.newUsers

Because getters.users is undefined. Instead you have to access it with bracket notation: this.$store.getters['users/newUsers']

This is true even though, without modules, I can access getters with dot notation:
this.$store.getters.newUsers

Is there a reason why this isn't possible with getters? It would be nice if we could access namespaced getters in the same way we can with namespaced state. This current behavior seems inconsistent.

What does the proposed API look like?

Given a users namespaced module, add the ability to access getters with: this.$store.getters.users.newUsers

@hootlex

This comment has been minimized.

Copy link
Member

hootlex commented Aug 2, 2018

@ktsn @kazupon what's your views on this one? I can look into it during the sprint 🙂

@ktsn

This comment has been minimized.

Copy link
Member

ktsn commented Aug 2, 2018

👍

@erfanimani

This comment has been minimized.

Copy link

erfanimani commented Jan 9, 2019

+1

It's actually pretty confusing for a beginner — I couldn't figure out how to call a namespaced getter method up until the point I stumbled upon this ticket and it all made sense (https://vuex.vuejs.org/guide/modules.html doesn't seem to explain that at all).

@sustained

This comment has been minimized.

Copy link

sustained commented Feb 23, 2019

I also find this pretty confusing, at least for new users. It's arguably fine once you know about it.

But a change like this would of course be backwards incompatible. However you could just keep the old names and add a deprecation notice to them, perhaps.

Anyway, yeah. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.