diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-06 08:59:07 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-06 09:04:42 +0200 |
| commit | 9dece1aae3fdbb34b719612db6b2ee3ae407da58 (patch) | |
| tree | 702d16485f967081c69981bad1091bc9786663fc /src | |
| parent | eb38ec3f771c6127f06fa1370922202e7d20607d (diff) | |
graph: unite both remove node actions for easier undo/diff tracking
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/graph.js | 32 |
1 files 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 |
