-
Notifications
You must be signed in to change notification settings - Fork 801
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
Investigate what it would take to support function properties #242
Comments
can you do that without a babel plugin? |
I don’t think so. But then again, you can’t have class properties without Babel anyway? |
yeah but then aren't we back to needing to identify classes that look like react components at compile time? |
No, this transform is harmless for any class. I just mean turning class Stuff {
doSomething = (e) => {
this.x(e.stuff())
}
} into class Stuff {
doSomething = (e) => {
return this.___doSomethingqwertyu234567(e);
},
___doSomethingqwertyu234567(e) {
this.x(e.stuff())
}
} I’m not sure if there is anything in the spec that would make it a bad idea but it’s worth giving it a shot. The only special case I see so far is |
Hmm, I see, we might hit some edge cases related to the differences between regular functions and arrow functions, so we should bail out on use of class Stuff {
doSomething = (e) => this.x(e.stuff())
} class Stuff {
doSomething = (e) => {
return this.___doSomethingqwertyu234567(e);
},
___doSomethingqwertyu234567(e) {
return this.x(e.stuff())
}
} so maybe it might be better to translate it to class Stuff {
doSomething = (e) => {
return this.___doSomethingqwertyu234567(e);
},
___doSomethingqwertyu234567(e) {
return ((e) => this.x(e.stuff()))(e)
}
} this way the function would still be an arrow function... on the other hand we're creating a function on every invocation... |
We need to create it once, otherwise it’s slow. I’m not really sure I see your point about functions without body. We can just convert them to arrow functions without body that call those hidden methods. Or we can bail out because most event handlers are more than one liners, and commonly React code uses those just for event handlers. Handling majority of cases is good enough here. |
yeah you're right, this doesn't need to work for everything. |
Yeah I get it, but if Babel is able to compile arrow functions correctly, so can we 😄 . Just a matter of having enough tests. |
…nctions into hot-reloadable class methods (gaearon#242)
…nctions into hot-reloadable class methods (gaearon#242)
e.g.
One way to approach this would be to hoist the bodies of the function properties into hidden methods on the prototype with mangled names. This would be unobservable to the user but make them available for
react-proxy
to see and hot reload.The text was updated successfully, but these errors were encountered: