mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
1359545e13
commit
0e035e47df
@ -1306,21 +1306,23 @@ RED.nodes = (function() {
|
||||
RED.events.on("registry:node-type-added",function(type) {
|
||||
var def = registry.getNodeType(type);
|
||||
var replaced = false;
|
||||
var replaceNodes = [];
|
||||
var replaceNodes = {};
|
||||
RED.nodes.eachNode(function(n) {
|
||||
if (n.type === "unknown" && n.name === type) {
|
||||
replaceNodes.push(n);
|
||||
replaceNodes[n.id] = n;
|
||||
}
|
||||
});
|
||||
RED.nodes.eachConfig(function(n) {
|
||||
if (n.type === "unknown" && n.name === type) {
|
||||
replaceNodes.push(n);
|
||||
replaceNodes[n.id] = n;
|
||||
}
|
||||
});
|
||||
|
||||
if (replaceNodes.length > 0) {
|
||||
var replaceNodeIds = Object.keys(replaceNodes);
|
||||
if (replaceNodeIds.length > 0) {
|
||||
var reimportList = [];
|
||||
replaceNodes.forEach(function(n) {
|
||||
replaceNodeIds.forEach(function(id) {
|
||||
var n = replaceNodes[id];
|
||||
if (configNodes.hasOwnProperty(n.id)) {
|
||||
delete configNodes[n.id];
|
||||
} else {
|
||||
@ -1328,6 +1330,18 @@ RED.nodes = (function() {
|
||||
}
|
||||
reimportList.push(convertNode(n));
|
||||
});
|
||||
|
||||
// Remove any links between nodes that are going to be reimported.
|
||||
// This prevents a duplicate link from being added.
|
||||
var removeLinks = [];
|
||||
RED.nodes.eachLink(function(l) {
|
||||
if (replaceNodes.hasOwnProperty(l.source.id) && replaceNodes.hasOwnProperty(l.target.id)) {
|
||||
removeLinks.push(l);
|
||||
}
|
||||
});
|
||||
removeLinks.forEach(removeLink);
|
||||
|
||||
|
||||
RED.view.redraw(true);
|
||||
var result = importNodes(reimportList,false);
|
||||
var newNodeMap = {};
|
||||
|
Loading…
Reference in New Issue
Block a user