diff --git a/src/utils/react-dfs.js b/src/utils/react-dfs.js new file mode 100644 index 00000000..ffefa1a4 --- /dev/null +++ b/src/utils/react-dfs.js @@ -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; \ No newline at end of file