diff --git a/src/core/structure/tree.js b/src/core/structure/tree.js index d79ac99ef..62f0e1d71 100644 --- a/src/core/structure/tree.js +++ b/src/core/structure/tree.js @@ -30,23 +30,26 @@ initTree: function (nodes) { var self = this; this.clear(); - var queue = []; + var queue = new Set(); + BI.each(nodes, function (i, node) { var n = new BI.Node(node); n.set("data", node); self.addNode(n); - queue.push(n); + queue.add(n); }); - while (!BI.isEmpty(queue)) { - var parent = queue.shift(); + + queue.forEach(parent => { + queue.delete(parent); + var node = parent.get("data"); BI.each(node.children, function (i, child) { var n = new BI.Node(child); n.set("data", child); - queue.push(n); + queue.add(n); self.addNode(parent, n); }); - } + }); }, _toJSON: function (node) {