1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Use onadd in link nodes to ensure imported links are updated

This commit is contained in:
Nick O'Leary 2016-05-18 16:48:16 +01:00
parent 3e9be9eed3
commit 5ad46106f4
3 changed files with 19 additions and 8 deletions

View File

@ -195,9 +195,6 @@ 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);

View File

@ -2208,6 +2208,14 @@ RED.view = (function() {
node.n.y -= minY; node.n.y -= minY;
node.dx -= minX; node.dx -= minX;
node.dy -= minY; node.dy -= minY;
if (node.n._def.onadd) {
try {
node.n._def.onadd.call(node.n);
} catch(err) {
console.log("onadd:",err);
}
}
} }
if (!touchImport) { if (!touchImport) {
mouse_mode = RED.state.IMPORT_DRAGGING; mouse_mode = RED.state.IMPORT_DRAGGING;
@ -2218,7 +2226,6 @@ RED.view = (function() {
node.n._def.outputs > 0; node.n._def.outputs > 0;
} }
} }
RED.keyboard.add("*",/* ESCAPE */ 27,function(){ RED.keyboard.add("*",/* ESCAPE */ 27,function(){
RED.keyboard.remove(/* ESCAPE */ 27); RED.keyboard.remove(/* ESCAPE */ 27);
clearSelection(); clearSelection();

View File

@ -236,16 +236,12 @@
i = n.links.indexOf(node.id); i = n.links.indexOf(node.id);
if (i > -1) { if (i > -1) {
n.links.splice(i,1); n.links.splice(i,1);
n.changed = true;
n.dirty = true;
} }
} else if (!nodeMap[id].old && nodeMap[id].new){ } else if (!nodeMap[id].old && nodeMap[id].new){
// Added id // Added id
i = n.links.indexOf(id); i = n.links.indexOf(id);
if (i === -1) { if (i === -1) {
n.links.push(node.id); n.links.push(node.id);
n.changed = true;
n.dirty = true;
} }
} }
} }
@ -253,6 +249,15 @@
} }
} }
function onAdd() {
for (var i=0;i<this.links.length;i++) {
var n = RED.nodes.node(this.links[i]);
if (n.links.indexOf(this.id) === -1) {
n.links.push(this.id);
}
}
}
RED.nodes.registerType('link in',{ RED.nodes.registerType('link in',{
category: 'input', category: 'input',
color:"#ddd",//"#87D8CF", color:"#ddd",//"#87D8CF",
@ -275,6 +280,7 @@
oneditsave: function() { oneditsave: function() {
onEditSave(this); onEditSave(this);
}, },
onadd: onAdd,
oneditresize: resizeNodeList oneditresize: resizeNodeList
}); });
@ -301,6 +307,7 @@
oneditsave: function() { oneditsave: function() {
onEditSave(this); onEditSave(this);
}, },
onadd: onAdd,
oneditresize: resizeNodeList oneditresize: resizeNodeList
}); });
})(); })();