[Ivan Diaz] - Add ReactDFS util

This commit is contained in:
Ivan Diaz 2015-09-17 22:17:50 -03:00
parent 960411b58a
commit 39a9b051e0
1 changed files with 19 additions and 0 deletions

19
src/utils/react-dfs.js vendored Normal file
View File

@ -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;