From 39a9b051e0e6f2dbd430daa72985fc436f16c757 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Thu, 17 Sep 2015 22:17:50 -0300 Subject: [PATCH] [Ivan Diaz] - Add ReactDFS util --- src/utils/react-dfs.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils/react-dfs.js 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