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

Supply SetupContext as first argument to SetupFunction. #154

Closed
Eckhardt-D opened this issue Oct 8, 2019 · 2 comments
Closed

Supply SetupContext as first argument to SetupFunction. #154

Eckhardt-D opened this issue Oct 8, 2019 · 2 comments

Comments

@Eckhardt-D
Copy link

Currently the setup function receives (props, context). Components won't always be fed props from the parent, but will always need the context, therefore I reason that the props argument must be made optional and context must be provided as the first argument.

What this solves:

Mainly developer experience eg:

setup(_, { emit }) {
  ...
}

Can become:

setup({ emit }) {
  ...
}

Avoiding redundant exclusion of props if not supplied by parent and developer has choice to access it or not.

@posva
Copy link
Member

posva commented Oct 8, 2019

Components won't always be fed props from the parent but will always need the context

That isn't true. You probably found yourself using the context but not the props multiple times and thought that but the opposite happens quite often as well. Remember this library is following the RFC at https://vue-composition-api-rfc.netlify.com/api.html#setup. The order has probably been discussed already but it's impossible for me to link you to the comments as there were way too many at vuejs/rfcs#42 and vuejs/rfcs#78.
Props are like function parameters, it makes sense for them to be first, since you shouldn't destructure them and access them through the parameter props directly, renaming it to _ only changes something during development.

@posva posva closed this as completed Oct 8, 2019
@Eckhardt-D
Copy link
Author

Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants