-
Notifications
You must be signed in to change notification settings - Fork 799
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
Autobind decorator #125
Comments
The exact message I get when trying this is |
You can try finding a fix by adding a failing test to react-hotify. Then, if you find a solution, I can backport it to RHL. |
@gaearon should I add test for work with autobind-decorator? |
@slonoed Yes, if you also find a fix. |
@slonoed It's also worth checking if this change helps (or makes it worse, I dunno) |
Dunno if much help, but here is a test for react-hotify for this problem (using core-decorators): import React, { Component } from 'react';
import createShallowRenderer from './helpers/createShallowRenderer';
import expect from 'expect.js';
import makeHotify from '../src/makeHotify';
import { autobind } from 'core-decorators';
class Bar {
@autobind
getProps() {
return typeof this.props;
}
render() {
return <div>{this.getProps()}</div>;
}
}
describe('autobind usage', function() {
let renderer;
let hotify;
beforeEach(() => {
renderer = createShallowRenderer();
hotify = makeHotify();
});
it('should bind methods of hotified components', function() {
const HotBar = hotify(Bar);
const barInstance = renderer.render(<HotBar />);
expect(renderer.getRenderOutput().props.children).to.equal('object');
});
}) |
Thanks! I'll definitely get back to this after my React Europe talk. |
Happy to help test possible fixes. Also wondering if this is a general problem interoperating with decorators in general, and if that should be the focus rather than |
For me this issue not actual now. I switch to arrow functions in class definition.
Can I close this issue? |
I've done the same, but consider it a temporary fix. I prefer the decorator approach (because I bind at the class level, not the method level). I will chime back in here if my other decorators have issues (I haven't gotten that far yet, this is my first hot-reload project). |
@slonoed this arrow function approach works? Will it always? I would have thought that in that scenario the arrow function would have made |
I am having issues with the arrow function, actually. The hot reloading does not apply when using |
@lancefisher I think there is no spec for arrow functions in class. @opatut why you want bind render? It is always called by library code, isnt it? |
It's not only about binding However, I find that binding the methods with
|
Properties are very tricky to hot reload because they're really being defined inside the constructor. |
We're supporting autobind decorator in the next beta release coming soon. |
Can I ask you to check whether |
|
@steadicat Hmm, I'm pretty sure fat arrow methods still shouldn't get hot reloaded. Can you check again, or share a reproducible case? |
(That said |
@gaearon You're right, it turns out I have a decorator on my components that somehow works around this issue. Here’s a reduced test case (code below): import React from 'react';
function wrap(Component) {
return class Wrapper {
render() {
return <Component {...this.props} />;
}
}
}
@wrap
export default class Test {
render() {
return this.renderInner();
}
renderInner = () => {
return <h1>Version 4</h1>;
}
} |
Oh. It works because it generates a new class on every invocation. The downside is |
I don't think this is fully working with Small test commit here. In the demo above there's 3 steps:
RHL doesn't remove the binding when using fat arrows to declare the method either. Hope that's helpful, would really love to use this with RHL! |
I'm having trouble too, no production ready example yet. It might make sense to reopen this issue. |
Add/removing |
got it! I moved to the beta and everything worked after I updated to node 6.x, so it is all good! |
I want to use autobind decorator for components.
This https://github.com/andreypopp/autobind-decorator/blob/master/src/index.js work fine with React (method binding).
But have issue with RHL. Decorator bind method to instance. When new RHL add new prototype to prototype chain nothing happened, because method already in instance and new method in proto not visible when getter called.
I use ugly hack and check in getter
if (this.props)
to determine is this – instance.It is not an issue with RHL or decorator itself. I try to find nice solution.
The text was updated successfully, but these errors were encountered: