summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-12-07 17:41:28 +0200
committerAlon Levy <alon@pobox.com>2014-12-16 10:59:14 +0200
commit9a57d84952d21ee86ae4c5363b84d0932c56fdc1 (patch)
tree96e3efd003825593f3f6ea368a8af73aa7c41f51
parentb67a7355196318d006479266bac2f035b48cf96d (diff)
__addNode(): assert id present on insertion,
introduce id_to_node_map
-rw-r--r--src/model/graph.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/model/graph.js b/src/model/graph.js
index 55b72302..fca38ef4 100644
--- a/src/model/graph.js
+++ b/src/model/graph.js
@@ -8,6 +8,7 @@ var debug = false;
function Graph() {
var nodes = [],
+ id_to_node_map = {},
links = [],
diffBus = new Bacon.Bus();
@@ -54,13 +55,16 @@ function Graph() {
node = model_core.create_node_from_spec(spec);
}
- existing_node = findNode(node.id, null);
+ existing_node = find_node__by_id(node.id);
if (existing_node) {
- console.debug('__addNode: id collision: existing-node.id: \'' + existing_node.id + '\', ' + 'new-node.id: \'' + node.id + '\'');
+ console.log('__addNode: id collision: existing-node.id: \'' + existing_node.id + '\', ' + 'new-node.id: \'' + node.id + '\'');
return existing_node;
}
+ util.assert(undefined != node.id, '__addNode: node id missing');
nodes.push(node);
+ id_to_node_map[node.id] = node;
+ console.log('__addNode: node added: id: ' + node.id);
if (notify) {
diffBus.push({nodes: {add: [node]}});
@@ -80,6 +84,9 @@ function Graph() {
var index = findNodeIndex(n.id, n.state);
if (index !== undefined) {
nodes.splice(index, 1);
+
+ util.assert(undefined != n.id, '_removeNodes: node id missing');
+ delete id_to_node_map[n.id];
}
}
if (ns.length > 0) {