zent
Version:
一套前端设计语言和基于React的实现
20 lines (19 loc) • 588 B
JavaScript
import { Forest } from './forest';
import { getNodeKey } from './node-fns';
export function simplify(paths, selectionMap) {
var forest = new Forest([]);
paths.forEach(function (p) { return forest.insertPath(p); });
forest.reduceNode(function (_, node) {
var k = getNodeKey(node);
var state = selectionMap.get(k);
if (state === 'on') {
node.children = [];
}
return _;
}, null);
var simplified = forest.reducePath(function (all, path) {
all.push(path);
return all;
}, []);
return simplified;
}