-
Notifications
You must be signed in to change notification settings - Fork 34
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
Support instance-as-result children #23
Conversation
Codecov Report
@@ Coverage Diff @@
## master #23 +/- ##
=========================================
+ Coverage 85.91% 86.3% +0.38%
=========================================
Files 1 1
Lines 71 73 +2
Branches 20 21 +1
=========================================
+ Hits 61 63 +2
Misses 8 8
Partials 2 2
Continue to review full report at Codecov.
|
src/index.js
Outdated
// - https://github.com/ctrlplusb/react-tree-walker/issues/19 | ||
// - https://github.com/gaearon/react-hot-loader/issues/832 | ||
// - https://github.com/gaearon/react-hot-loader/blob/master/src/proxy/utils.js#L84 | ||
const theChild = child && typeof child.render === 'function' |
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.
Could one intermediate component return another?
Maybe this should be recursive.
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.
Do you mean something like this:
// as a helper at root level:
const flattenChild = component => (
component && typeof component.render === 'function'
? flattenChild(component.render())
: component
);
// then inside doTraverse function:
const child = getChildren();
const theChild = flattenChild(child);
or
// inside doTraverse function:
let child = getChildren();
while (child && typeof child.render === 'function') {
child = child.render();
}
I'm not sure which one is better here yet
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.
I'll prefer the first one. It is just testable, and look like code coverage is a thing here.
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.
I'll update shortly. Meanwhile, if you have time, can you help me on having some tests for this? Like how to have a sample child with render
... Maybe something like this?
const Foo = () => (
() => <span>abc</span>
);
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.
class MyComponent extends Component { render() { return <div /> }}
const Foo = (props) => new MyComponent(props);
So - in case of "instance" in tree - just "skip" it by rendering, and dive deeper. |
@theKashey I added a test and add support for recursive calling render until we have a valid React child. |
03783a5
to
4425daf
Compare
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.
Looks good, can you merge and release @ctrlplusb
This is necessary for react-universally @ next
Thanks so much for this @dvkndn! And for @theKashey and @birkir for the review 👍 |
Support instance-as-result children
Fixes #19