[Ivan Diaz] - Add ReactDFS util
This commit is contained in:
parent
960411b58a
commit
39a9b051e0
|
@ -0,0 +1,19 @@
|
|||
import React from 'react/addons';
|
||||
|
||||
var reactDFS = function (children, visitFunction) {
|
||||
var stack = [];
|
||||
|
||||
React.Children.forEach(children, child => stack.push(child));
|
||||
stack.reverse();
|
||||
|
||||
while(stack.length) {
|
||||
let element = stack.pop();
|
||||
let tempChilds = [];
|
||||
React.Children.forEach(element.props.children, child => tempChilds.push(child));
|
||||
|
||||
visitFunction(element);
|
||||
stack.concat(tempChilds.reverse());
|
||||
}
|
||||
};
|
||||
|
||||
export default reactDFS;
|
Loading…
Reference in New Issue