Open xereda opened 5 years ago
That is historical reason. At the beginning, the getters does not look like the current API and it only receives state object. Because changing the argument shape is breaking change, we added the extra values like getters and rootState as additional parameters.
We may change the getter parameters to the same shape as actions in the next major release.
What problem does this feature solve?
Is there a specific reason for a getter to get store context through separate arguments?
I like how the actions receive the context of the store, that is, with only one argument, this being an object. With this, we have the possibility of using es6 destructuring to extract something specific.
If I just need to trigger a mutation (the most common behavior), I just to extract commit from context object. But, if I need to access a getter from a parent module, for example, I extract together with dispatch, the rootGetters.
Although they are exceptional cases, I have some situations that I need, inside a getter, access a getter from another module (parent module). With this, I need to inform arguments that I will not use in the getter scope.
Analyze the following example:
See that I have passed the getters and rootState arguments, even though, in this case, I do not need them.
The question I have is: Is there any specific reason why it has been treated differently from how it is handled in the vuex actions? Why does an vuex action get only one argument and vuex getter get 4 arguments?
Thanks in advance for the time spent by friends. Sorry for bad English.
What does the proposed API look like?
Just document, through this issue, the difference between the behavior of getters and actions.