Use RED.nodes.filterLinks in pref to RED.nodes.eachLink

This commit is contained in:
Nick O'Leary 2015-03-15 23:41:16 +00:00
parent cf8fe16b09
commit 9c104faff3
3 changed files with 5 additions and 9 deletions

View File

@ -813,6 +813,9 @@ RED.nodes = (function() {
continue;
}
}
if (filter.sourcePort && link.sourcePort !== filter.sourcePort) {
continue;
}
result.push(link);
}
return result;

View File

@ -114,11 +114,7 @@ RED.editor = (function() {
}
}
if (node.inputs === 0) {
RED.nodes.eachLink(function(l) {
if (l.target === node) {
removedLinks.push(l);
}
});
removedLinks.concat(RED.nodes.filterLinks({target:node}));
}
for (var l=0;l<removedLinks.length;l++) {
RED.nodes.removeLink(removedLinks[l]);

View File

@ -929,10 +929,7 @@ RED.view = (function() {
dst = mousedown_node;
src_port = portIndex;
}
var existingLink = false;
RED.nodes.eachLink(function(d) {
existingLink = existingLink || (d.source === src && d.target === dst && d.sourcePort == src_port);
});
var existingLink = RED.nodes.filterLinks({source:src,target:dst,sourcePort: src_port}).length !== 0;
if (!existingLink) {
var link = {source: src, sourcePort:src_port, target: dst};
RED.nodes.addLink(link);