Better API consistency, IMHO.
There are getters, mutations and actions.
As for mutations, you use the $store.commit('mutation-name', stuff) syntax while for actions you do $store.dispatch('action-name', stuff), which is really nice. But, as for getters, the current approach is $store.getters.getter-name.
From a user perspective, I think there's a nicer option that wouldn't also break backwards compatibility since both ways could coexist without any problem.
Similar to mutations and actions, I think $store.getter('getter-name') could be a better way to call getters.
This way the syntax for getters, mutations and actions would be more similar:
$store.getter('name')
$store.commit('name', data)
$store.dispatch('name', data)
Note: I'm not specifically proposing .getter('name'). It may be something else like .fetch(...) or .pull(...) or whatever (the best thing would have been $store.get('name') in my opinion, but .get is already a JavaScript method on objects so... no way I guess). What I mean is to use a function call like what happens to "use" mutations and actions.
I understand this is totally subjective and I am not expecting everyone to agree on this proposal, but I see this approach as a much cleaner and consistent one.
Also, I understand this is just a minor "thing" (not even a problem) but I wanted to express my idea anyway in case someone else would find this interesting and/or having any sense.
I think getters should be property access since it has a different concept with actions/mutations.
We pass a actions/mutations name string to dispatch/commit because it follows the observer pattern - someone fires an event while another can observe it. Also as it can dispatch/commit multiple actions/mutations which belong the same name it would appropriate such EvenEmitter like interface.
On the other hand, getters are just like computed properties on Vue components and it cannot have multiple getters that belong the same name. I think it would be weird if we change the getter interface to the similar form with actions/mutations.
Getters are computed properties, So I think they should be accessed just like them.
Now I got it, it seems totally reasonable to keep everything as it is. While reading through the docs I soon noticed this difference without thinking a lot about why it has been done this way, but now I totally get the point.
I think this can be closed, thank you for the clarification!
Most helpful comment
I think getters should be property access since it has a different concept with actions/mutations.
We pass a actions/mutations name string to
dispatch/commitbecause it follows the observer pattern - someone fires an event while another can observe it. Also as it can dispatch/commit multiple actions/mutations which belong the same name it would appropriate such EvenEmitter like interface.On the other hand, getters are just like computed properties on Vue components and it cannot have multiple getters that belong the same name. I think it would be weird if we change the getter interface to the similar form with actions/mutations.