mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add onadd/onremove event handlers to node definitions
This commit is contained in:
parent
bbd197c71d
commit
a27353c166
@ -160,13 +160,13 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
nodes.push(n);
|
nodes.push(n);
|
||||||
}
|
}
|
||||||
|
if (n._def.onadd) {
|
||||||
|
n._def.onadd.call(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function addLink(l) {
|
function addLink(l) {
|
||||||
links.push(l);
|
links.push(l);
|
||||||
}
|
}
|
||||||
function addConfig(c) {
|
|
||||||
configNodes[c.id] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNode(id) {
|
function getNode(id) {
|
||||||
if (id in configNodes) {
|
if (id in configNodes) {
|
||||||
@ -183,11 +183,13 @@ RED.nodes = (function() {
|
|||||||
|
|
||||||
function removeNode(id) {
|
function removeNode(id) {
|
||||||
var removedLinks = [];
|
var removedLinks = [];
|
||||||
|
var node;
|
||||||
if (id in configNodes) {
|
if (id in configNodes) {
|
||||||
|
node = configNodes[id];
|
||||||
delete configNodes[id];
|
delete configNodes[id];
|
||||||
RED.sidebar.config.refresh();
|
RED.sidebar.config.refresh();
|
||||||
} else {
|
} else {
|
||||||
var node = getNode(id);
|
node = getNode(id);
|
||||||
if (node) {
|
if (node) {
|
||||||
nodes.splice(nodes.indexOf(node),1);
|
nodes.splice(nodes.indexOf(node),1);
|
||||||
removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); });
|
removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); });
|
||||||
@ -214,6 +216,9 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (node._def.onremove) {
|
||||||
|
node._def.onremove.call(n);
|
||||||
|
}
|
||||||
return removedLinks;
|
return removedLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,6 +763,7 @@ RED.nodes = (function() {
|
|||||||
delete output.wires;
|
delete output.wires;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return [new_nodes,new_links,new_workspaces,new_subflows];
|
return [new_nodes,new_links,new_workspaces,new_subflows];
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
if (error.code != "NODE_RED") {
|
if (error.code != "NODE_RED") {
|
||||||
|
Loading…
Reference in New Issue
Block a user