From 9dece1aae3fdbb34b719612db6b2ee3ae407da58 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Sat, 6 Dec 2014 08:59:07 +0200 Subject: graph: unite both remove node actions for easier undo/diff tracking --- src/model/graph.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/model/graph.js b/src/model/graph.js index de9cddd7..4a2e1f0c 100644 --- a/src/model/graph.js +++ b/src/model/graph.js @@ -69,23 +69,7 @@ function Graph() { return node; } - this.removeNode = function(id, state) { - var i = 0; - var n = findNode(id, state); - while (i < links.length) { - if ((links[i]['__src'] === n) || (links[i]['__dst'] == n)) links.splice(i, 1); - else i++; - } - var index = findNodeIndex(id, state); - if (index !== undefined) { - nodes.splice(index, 1); - } - diffBus.push({nodes: {removed: [id]}}); - } - - this.removeNodes = function(state) { - var id = null; - var ns = findNodes(null, state); + this._removeNodes = function(ns) { for (var j = 0; j < ns.length; j++) { var n = ns[j]; var i = 0; @@ -93,7 +77,7 @@ function Graph() { if ((links[i]['__src'] === n) || (links[i]['__dst'] == n)) links.splice(i, 1); else i++; } - var index = findNodeIndex(id, state); + var index = findNodeIndex(n.id, n.state); if (index !== undefined) { nodes.splice(index, 1); } @@ -103,6 +87,18 @@ function Graph() { } } + this.removeNode = function(id, state) { + var i = 0; + var n = findNode(id, state); + this._removeNodes([n]); + } + + this.removeNodes = function(state) { + var id = null; + var ns = findNodes(null, state); + this._removeNodes(ns); + } + /** * * getConnectedNodesAndLinks -- cgit v1.3.1