-
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
Will this convention be supported? #427
Comments
The problem is that React Hot Loader can't hot-reload the constructor without the component being re-instantiated (and remounting/losing its state). It can reload class methods, though, so part of our Babel plugin actually deals with this by copying the class property bodies to class methods, see this discussion. We could probably do the exact same transform to support this pattern. I don't have much time to implement this right now, but I'd be happy to give some pointers to someone who wants to try it. 😄 |
I want to try. Where should I start? |
First, I recommend reading through babel-handbook if you haven't already, it's amazing. Also, AST Explorer is really useful for understanding JS ASTs. Also, babel-types is your best friend for creating new AST nodes. The best way to understand what the Babel plugin does is to look at the test fixtures, for expected input/output. It's probably best to create more fixtures in this style as test cases for the new behavior. This part of the plugin deals with finding class properties, creating new methods, and creating the class property that just proxies to the new method. You can probably look for (arrow) functions defined on Hope that's helpful! |
This is what I need. Thank you so much! I'll give a shot soon. |
I've been doing the method prescribed in this link and having an issue with alias pollution. Every reload ceates an alias for every class method (bound handler). http://reactkungfu.com/2015/07/why-and-how-to-bind-methods-in-your-react-component-classes/ So basically:
With the downside being hot loader creates aliases every time it reloads. So you end up with this grossness:
|
@paulpooch you're talking about something different from the original issue. can you move that comment to a new issue please? I don't want the prior discussion to get sidetracked with a separate topic. |
@calesce How to visit
|
I think I found the solution of the first question. {
ClassMethod (path) {
path.traverse({
AssignmentExpression(path) {
// ...
}
});
}
} |
I don't want to use
this.handleSliderMouseDown = this.handleSliderMouseDown.bind(this)
because this is too verbose. Also I don't want to apply the experimental syntax,property-initializers
.So, I've been binding function by declaring an arrow function inside of constructor.
It works well as long as i use only HMR without React hot loader.
If I use HMR, instance methods aren't refreshed because constructor won't be fired again.
Can I use this syntax and wait the fix? Or should I stop using it?
The text was updated successfully, but these errors were encountered: