3.0.0-alpha.1
I accidentally noticed that if I write setup function like this, I will not receive the context parameter.
export default {
setup(...args) {
console.log(args[1]) // null
}
}
args[1] is context
args[1] is null
I found why:
https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/src/component.ts#L293
I know most people won't write like this, but it's a little weird for me.
Just for discuss.
It saves creating two proxy instances if the argument isn't used.
@KaelWD I know. But this is a trap, is it worth it? Maybe document it will help.
I don't think you are supposed to destructure the 2 arguments of setup like that.
Being able to avoid creating the Context object altogether for components not using it (all components that only rely on props) is a big perf boost. The only possible reason to use the spread like that is to pass the args again to a different function using the spread operator, so I think this is perfectly fine given the perf benefit
@posva I agree. And I think there needs to be some way to let people know about this, before they run into it, document maybe (in the future)?
How did you personally run into it and do you have any idea of other ways people will run into it? This will helps us to find the place it fits in the docs. Since most people won't use that syntax naturally nor by following the guide, it needs to be in the right place to be effective
I'm doing a small experiment, want to log both props and context, but I'm to lazy to write two parameters馃槄. Maybe people will write code like this when they debugging.
I see 馃槅
To me this is the kind of cases most people won't hit and when they do, they should be able to find a forum post or issue with the reasoning.
Putting it on the docs as a tip adds mental overhead that will be useless to most users and it's something we are avoiding and, instead, trying to integrate the explanation with the guide, to make the learning experience smoother
Side note: talking about laziness, using one letters for debugging purposes is even shorter and about as bad in readability as using the spread operator 馃槃 :
export default {
setup(p, c) {
console.log(c)
}
}
I got your point, nice discussion.
Most helpful comment
I see 馃槅
To me this is the kind of cases most people won't hit and when they do, they should be able to find a forum post or issue with the reasoning.
Putting it on the docs as a tip adds mental overhead that will be useless to most users and it's something we are avoiding and, instead, trying to integrate the explanation with the guide, to make the learning experience smoother
Side note: talking about laziness, using one letters for debugging purposes is even shorter and about as bad in readability as using the spread operator 馃槃 :