-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Wrap render method created using class properties. #850
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,18 @@ export default (handleError = () => {}) => { | |
const { prototype } = Component | ||
if (prototype && prototype.render) { | ||
prototype.render = wrapRender(prototype.render) | ||
} else if (prototype && prototype.constructor) { | ||
// Still a React component instance, but there's no render method in | ||
// prototype. This happens when the render method created with class-properties. | ||
// With this fix, we'll wrap the render method in runtime when the component initialized | ||
const originalComponentWillMount = prototype.componentWillMount | ||
prototype.componentWillMount = function (...args) { | ||
if (originalComponentWillMount) { | ||
originalComponentWillMount.apply(this, args) | ||
} | ||
|
||
this.render = wrapRender(this.render) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should redefine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm quite not sure about that. This constructor function is something generated by babel. I just used that to detect a React component. |
||
} else { | ||
// stateless component | ||
Component = wrapRender(Component) | ||
|
@@ -54,7 +66,6 @@ export default (handleError = () => {}) => { | |
|
||
// copy all properties | ||
Object.assign(_render, render) | ||
|
||
render.__wrapped = _render.__wrapped = _render | ||
|
||
return _render | ||
|
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.
btw there may be
render
but might override it on constructor.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.
Since we do this on the
componentWillMount
. I assume this is fine.Isn't it?
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.
For now, we don't monkeypatch
componentWillMount
ifprototype.render
exists.