From 58c2f5dd3d5754abc3b0c36a409f00a3986b4819 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 7 Aug 2014 22:20:06 +0100 Subject: [PATCH] Add remove node api --- red/nodes/index.js | 5 ++++- red/nodes/registry.js | 23 ++++++++++++----------- red/server.js | 26 +++++++++++++++++++++++++- test/red/nodes/index_spec.js | 22 +++++++++++++++++++--- test/red/nodes/registry_spec.js | 17 +++++++++++++++++ 5 files changed, 77 insertions(+), 16 deletions(-) diff --git a/red/nodes/index.js b/red/nodes/index.js index ec48b18d2..4988a6840 100644 --- a/red/nodes/index.js +++ b/red/nodes/index.js @@ -54,6 +54,9 @@ function init(_settings,storage) { function removeNode(info) { var nodeInfo = registry.getNodeInfo(info); + if (!nodeInfo) { + throw new Error("Unrecognised type/id: "+info); + } var inUse = {}; flows.each(function(n) { inUse[n.type] = (inUse[n.type]||0)+1; @@ -66,7 +69,7 @@ function removeNode(info) { }); if (nodesInUse.length > 0) { var msg = nodesInUse.join(", "); - throw Error("Type in use: "+msg); + throw new Error("Type in use: "+msg); } return registry.removeNode(nodeInfo.id); } diff --git a/red/nodes/registry.js b/red/nodes/registry.js index 236ba61a0..febf92928 100644 --- a/red/nodes/registry.js +++ b/red/nodes/registry.js @@ -61,18 +61,19 @@ var registry = (function() { }, removeNode: function(id) { var config = nodeConfigs[id]; - if (config) { - delete nodeConfigs[id]; - var i = nodeList.indexOf(id); - if (i > -1) { - nodeList.splice(i,1); - } - config.types.forEach(function(t) { - delete nodeConstructors[t]; - delete nodeTypeToId[t]; - }); - nodeConfigCache = null; + if (!config) { + throw new Error("Unrecognised id: "+id); } + delete nodeConfigs[id]; + var i = nodeList.indexOf(id); + if (i > -1) { + nodeList.splice(i,1); + } + config.types.forEach(function(t) { + delete nodeConstructors[t]; + delete nodeTypeToId[t]; + }); + nodeConfigCache = null; return filterNodeInfo(config); }, getNodeInfo: function(typeOrId) { diff --git a/red/server.js b/red/server.js index 5961b96ac..3f8de61fe 100644 --- a/red/server.js +++ b/red/server.js @@ -70,6 +70,10 @@ function createServer(_server,_settings) { } redNodes.addNode(node).then(function(info) { comms.publish("node/added",info,false); + util.log("[red] Added node types:"); + for (var i=0;i