UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

28 lines (24 loc) 996 B
export function treeReduce(nodes, fn, initialValue) { var childName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'children'; var parentNode = arguments.length > 4 ? arguments[4] : undefined; return nodes.reduce(function (previousValue, node, index) { var newValue = fn(previousValue, node, index, parentNode); var children = node[childName]; if (children && children.length) { return treeReduce(children, fn, newValue, childName, node); } return newValue; }, initialValue); } export function treeForEach(nodes, fn) { var childName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; var parentNode = arguments.length > 3 ? arguments[3] : undefined; nodes.forEach(function (node, index) { fn(node, index, parentNode); var children = node[childName]; if (children && children.length) { treeForEach(children, fn, childName, node); } }); } //# sourceMappingURL=treeUtils.js.map