1
0
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:
Nick O'Leary 2019-01-29 21:49:20 +00:00
parent d23b32a830
commit d534a8952d
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 74 additions and 6 deletions

View File

@ -281,11 +281,13 @@ class Flow {
/**
* Get a node instance from this flow. If the node is not known to this
* 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]
*/
getNode(id) {
// console.log('getNode',id,!!this.activeNodes[id])
getNode(id, cancelBubble) {
if (!id) {
return undefined;
}
@ -298,7 +300,10 @@ class Flow {
// TEMP: this is a subflow internal node within this flow
return this.activeNodes[id];
}
return this.parent.getNode(id);
if (!cancelBubble) {
return this.parent.getNode(id);
}
return undefined;
}
/**

View File

@ -207,11 +207,11 @@ function setFlows(_config,type,muteLog,forceStart) {
function getNode(id) {
var node;
if (activeNodesToFlow[id] && activeFlows[activeNodesToFlow[id]]) {
return activeFlows[activeNodesToFlow[id]].getNode(id);
return activeFlows[activeNodesToFlow[id]].getNode(id,true);
}
for (var flowId in activeFlows) {
if (activeFlows.hasOwnProperty(flowId)) {
node = activeFlows[flowId].getNode(id);
node = activeFlows[flowId].getNode(id,true);
if (node) {
return node;
}

View File

@ -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() {
it("passes a status event to the adjacent status node",function(done) {