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 getters arguments #1467

Open
xereda opened this Issue Dec 7, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@xereda
Copy link

xereda commented Dec 7, 2018

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:

isLoading: (state, getters, rootState, rootGetters) => {
  // getters and rootState not used
  return state.isLoading || rootGetters.module.isLoading;
};

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment