-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Alternative fix for #3508 #3811
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
Conversation
src/runtime/internal/Component.ts
Outdated
if (component.$$.props.indexOf(name) === -1) return; | ||
component.$$.bound[name] = callback; | ||
callback(component.$$.ctx[name]); | ||
if (component.$$.props.hasOwnProperty(name)) { |
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.
Linting doesn't like using Object.prototype.hasOwnProperty
apparently - and probably for good reason, as I think this would get messed up with a prop called hasOwnProperty
. What I had meant before was actually using Object.hasOwnProperty(component.$$.props, name)
.
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.
wait, when did hasOwnProperty
become a static method on Object
? It works in Chrome, but does it work everywhere? I always used to do Object.prototype.hasOwnProperty.call(obj, prop)
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.
Apparently I'm going crazy. I just found this SO question, asked a mere three days ago. It sounds like Object.hasOwnProperty
doesn't really exist, but, because of javascript mysteries, you can call it, but it doesn't actually do what I expected. Sorry about that! Object.prototype.hasOwnProperty.call(component.$$.props, name)
sounds safest.
Edit: Or ({}).hasOwnProperty.call(...)
to save bytes, I guess. I don't know whether that's a performance hit.
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.
Turns out we're using hasOwnProperty
somewhere already so I turned it into a has_prop
helper
This is an alternative to #3809 (fixes #3508). It feels like a bit of a hack, but if we replace the array passed to the end of
init
with an object whose values are zeroes......then we can add renamed properties to the same object...
...and handle aliased exports while adding slightly less code:
I don't feel great about it, but it works. @Conduitry thoughts?