mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Do not propagate Flow.getNode to parent when called from outside flow
This commit is contained in:
parent
d23b32a830
commit
d534a8952d
@ -281,11 +281,13 @@ class Flow {
|
|||||||
/**
|
/**
|
||||||
* Get a node instance from this flow. If the node is not known to this
|
* Get a node instance from this flow. If the node is not known to this
|
||||||
* flow, pass the request up to the parent.
|
* flow, pass the request up to the parent.
|
||||||
* @param {[type]} id [description]
|
* @param {String} id [description]
|
||||||
|
* @param {Boolean} cancelBubble if true, prevents the flow from passing the request to the parent
|
||||||
|
* This stops infinite loops when the parent asked this Flow for the
|
||||||
|
* node to begin with.
|
||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
getNode(id) {
|
getNode(id, cancelBubble) {
|
||||||
// console.log('getNode',id,!!this.activeNodes[id])
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -298,8 +300,11 @@ class Flow {
|
|||||||
// TEMP: this is a subflow internal node within this flow
|
// TEMP: this is a subflow internal node within this flow
|
||||||
return this.activeNodes[id];
|
return this.activeNodes[id];
|
||||||
}
|
}
|
||||||
|
if (!cancelBubble) {
|
||||||
return this.parent.getNode(id);
|
return this.parent.getNode(id);
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all of the nodes instantiated within this flow
|
* Get all of the nodes instantiated within this flow
|
||||||
|
@ -207,11 +207,11 @@ function setFlows(_config,type,muteLog,forceStart) {
|
|||||||
function getNode(id) {
|
function getNode(id) {
|
||||||
var node;
|
var node;
|
||||||
if (activeNodesToFlow[id] && activeFlows[activeNodesToFlow[id]]) {
|
if (activeNodesToFlow[id] && activeFlows[activeNodesToFlow[id]]) {
|
||||||
return activeFlows[activeNodesToFlow[id]].getNode(id);
|
return activeFlows[activeNodesToFlow[id]].getNode(id,true);
|
||||||
}
|
}
|
||||||
for (var flowId in activeFlows) {
|
for (var flowId in activeFlows) {
|
||||||
if (activeFlows.hasOwnProperty(flowId)) {
|
if (activeFlows.hasOwnProperty(flowId)) {
|
||||||
node = activeFlows[flowId].getNode(id);
|
node = activeFlows[flowId].getNode(id,true);
|
||||||
if (node) {
|
if (node) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -413,6 +413,69 @@ describe('Flow', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
describe('#getNode',function() {
|
||||||
|
it("gets a node known to the flow",function(done) {
|
||||||
|
var config = flowUtils.parseConfig([
|
||||||
|
{id:"t1",type:"tab"},
|
||||||
|
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
|
||||||
|
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
|
||||||
|
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
|
||||||
|
{id:"4",z:"t1",type:"test",foo:"a"}
|
||||||
|
]);
|
||||||
|
var flow = Flow.create({},config,config.flows["t1"]);
|
||||||
|
flow.start();
|
||||||
|
|
||||||
|
Object.keys(flow.getActiveNodes()).should.have.length(4);
|
||||||
|
|
||||||
|
flow.getNode('1').should.have.a.property('id','1');
|
||||||
|
|
||||||
|
flow.stop().then(() => { done() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes to parent if node not known locally",function(done) {
|
||||||
|
var config = flowUtils.parseConfig([
|
||||||
|
{id:"t1",type:"tab"},
|
||||||
|
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
|
||||||
|
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
|
||||||
|
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
|
||||||
|
{id:"4",z:"t1",type:"test",foo:"a"}
|
||||||
|
]);
|
||||||
|
var flow = Flow.create({
|
||||||
|
getNode: id => { return {id:id}}
|
||||||
|
},config,config.flows["t1"]);
|
||||||
|
flow.start();
|
||||||
|
|
||||||
|
Object.keys(flow.getActiveNodes()).should.have.length(4);
|
||||||
|
|
||||||
|
flow.getNode('1').should.have.a.property('id','1');
|
||||||
|
|
||||||
|
flow.getNode('parentNode').should.have.a.property('id','parentNode');
|
||||||
|
|
||||||
|
|
||||||
|
flow.stop().then(() => { done() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not pass to parent if cancelBubble set",function(done) {
|
||||||
|
var config = flowUtils.parseConfig([
|
||||||
|
{id:"t1",type:"tab"},
|
||||||
|
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
|
||||||
|
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
|
||||||
|
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
|
||||||
|
{id:"4",z:"t1",type:"test",foo:"a"}
|
||||||
|
]);
|
||||||
|
var flow = Flow.create({
|
||||||
|
getNode: id => { return {id:id}}
|
||||||
|
},config,config.flows["t1"]);
|
||||||
|
flow.start();
|
||||||
|
|
||||||
|
Object.keys(flow.getActiveNodes()).should.have.length(4);
|
||||||
|
|
||||||
|
flow.getNode('1').should.have.a.property('id','1');
|
||||||
|
|
||||||
|
should.not.exist(flow.getNode('parentNode',true));
|
||||||
|
flow.stop().then(() => { done() });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#handleStatus",function() {
|
describe("#handleStatus",function() {
|
||||||
it("passes a status event to the adjacent status node",function(done) {
|
it("passes a status event to the adjacent status node",function(done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user