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

Add SubflowModule class for running subflow modules

This commit is contained in:
Nick O'Leary 2020-09-02 19:33:31 +01:00 committed by Nick O'Leary
parent 0c9fd25d3e
commit 814fc8bc69
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 41 additions and 2 deletions

View File

@ -504,11 +504,49 @@ function remapSubflowNodes(nodes,nodeMap) {
} }
} }
class SubflowModule extends Subflow {
/**
* Create a Subflow Module object.
* This is a node that has been published as a subflow.
* @param {[type]} parent [description]
* @param {[type]} globalFlow [description]
* @param {[type]} subflowDef [description]
* @param {[type]} subflowInstance [description]
*/
constructor(type, parent,globalFlow,subflowDef,subflowInstance) {
super(parent,globalFlow,subflowDef,subflowInstance);
this.TYPE = `module:${type}`;
this.subflowType = type;
}
/**
* [log description]
* @param {[type]} msg [description]
* @return {[type]} [description]
*/
log(msg) {
if (msg.id) {
msg.id = this.id
}
if (msg.type) {
msg.type = this.subflowType
}
super.log(msg);
}
}
function createSubflow(parent,globalFlow,subflowDef,subflowInstance) { function createSubflow(parent,globalFlow,subflowDef,subflowInstance) {
return new Subflow(parent,globalFlow,subflowDef,subflowInstance) return new Subflow(parent,globalFlow,subflowDef,subflowInstance)
} }
function createModuleInstance(type, parent,globalFlow,subflowDef,subflowInstance) {
return new SubflowModule(type, parent,globalFlow,subflowDef,subflowInstance);
}
module.exports = { module.exports = {
init: function(runtime) {}, init: function(runtime) {},
create: createSubflow create: createSubflow,
createModuleInstance: createModuleInstance
} }

View File

@ -120,7 +120,8 @@ function createNode(flow,config) {
} }
}) })
var subflow = require("./Subflow").create( var subflow = require("./Subflow").createModuleInstance(
nodeTypeConstructor.type,
flow, flow,
flow.global, flow.global,
subflowConfig.subflows[nodeTypeConstructor.subflow.id], subflowConfig.subflows[nodeTypeConstructor.subflow.id],