UNPKG

choerodon-ui

Version:

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

37 lines (30 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.treeReduce = treeReduce; exports.treeForEach = treeForEach; 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); } 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