Skip to content

Commit 4c15228

Browse files
authored
Merge pull request #10 from grxy/master
Fix issue with nested children, update unit tests, close #9
2 parents 09b4ce3 + 387a9e9 commit 4c15228

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/__tests__/index.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('reactTreeWalker', () => {
2424
}
2525

2626
render() {
27-
return <div>{this.props.children}</div>
27+
return this.props.children
2828
}
2929
}
3030

@@ -46,6 +46,7 @@ describe('reactTreeWalker', () => {
4646
<Bob>
4747
<Foo something={async ? () => resolveLater(4) : 4}>
4848
<Foo something={async ? () => resolveLater(5) : 5} />
49+
<Foo something={async ? () => resolveLater(6) : 6} />
4950
</Foo>
5051
</Bob>
5152
<div>hi!</div>
@@ -66,7 +67,7 @@ describe('reactTreeWalker', () => {
6667
}
6768
}
6869
return reactTreeWalker(tree, visitor).then(() => {
69-
const expected = [1, 2, 4, 5, 3]
70+
const expected = [1, 2, 4, 5, 6, 3]
7071
expect(actual).toEqual(expected)
7172
})
7273
})
@@ -85,7 +86,7 @@ describe('reactTreeWalker', () => {
8586
return true
8687
}
8788
return reactTreeWalker(tree, visitor).then(() => {
88-
const expected = [1, 2, 4, 5, 3]
89+
const expected = [1, 2, 4, 5, 6, 3]
8990
expect(actual).toEqual(expected)
9091
})
9192
})

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default function reactTreeWalker(element, visitor, context, options = def
6868
if (child == null) {
6969
// If no children then we can't traverse. We've reached the leaf.
7070
resolve()
71-
} else if (isChildren) {
71+
} else if (isChildren || Children.count(child)) {
7272
// If its a react Children collection we need to breadth-first
7373
// traverse each of them.
7474
const mapper = aChild =>

0 commit comments

Comments
 (0)