-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
introduce $$rest #4489
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
introduce $$rest #4489
Conversation
3ab4396
to
232988f
Compare
src/runtime/internal/utils.ts
Outdated
const rest = {}; | ||
keys = new Set(keys); | ||
for (const k in props) if (!keys.has(k) && k[0] !== '$') rest[k] = props[k]; | ||
return Object.freeze(rest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason to freeze this when $$props
isn't frozen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just think that $$rest
shouldn't be mutated, because it's kind of derived from $$props
, and mutation on $$rest
will not propagate back to the $$props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to be ironed out before this can get merged, but what are your thoughts on allowing $$props
to be mutated? I think that right now it can but those changes won't be reflected in the corresponding other variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, initially I was thinking of only freezing in dev mode, to educate users not to mutate it.
Not sure Object.freeze has any performance penalties...
What do u think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On another thought, I remove the freeze for now, to be consistent with the $$props.
In a separate PR, I'll add warnings for assignment or mutation on $$props and $$rest
We currently disable the dev-mode 'component was created with unknown prop foo' warning when a component uses |
I see in #2930 that |
I'm not familiar with vue, but reading their docs on $attr, https://vuejs.org/v2/guide/components-props.html#Disabling-Attribute-Inheritance, it is not exactly the same concept of what we have.. Naming is hard, that's why I just use whatever you suggested... Maybe some other suggestions:
Since it's a local variable, I reckon it's minifyable, long names should be fine. |
0ef3ecc
to
7d4ecba
Compare
3548cef
to
77c393e
Compare
Merged, thank you! I've removed the tutorial page for now because if we're going to mention |
introduce $$restProps (sveltejs#4489)
Wow, this is weird stuff... just came to know about this throught some google search. |
Fixes #2930
Based on @Conduitry's comment #3015 (comment)