calling AddFlow on RED api; subflows rejected

220 views
Skip to first unread message

Simon H

unread,
Dec 8, 2016, 4:47:52 AM12/8/16
to Node-RED
Hi all,

I'm using RED.nodes.addFlow() to add a flow to node-red programatically.  But if the flow contains a subflow (e.g. when exported to library), the flow is not loaded.  In the addFlow function (in red/runtime/nodes/flows/index.js), it specifically rejects nodes of type 'subflow'.

Is there some other function i should be using, or will i need to parse the flow more deeply and 'unwrap' the flow before loading?
Or are there any changes in the development trunk which may help?

best regards,

Simon
(V0.15.2)

Simon H

unread,
Dec 8, 2016, 3:23:44 PM12/8/16
to Node-RED
as an update to this,

I went with expansion of the subflows, adding empty 'function' modules to represent the input and output items in a subflow (else you are faced with a total recalculation of all connections).  I also went with setting a 'z' for configuration nodes (so they get deleted with the flow, which i will auto-delete on complete), since I anticipate any i will want to use will be duplicatable...
Someday my 'adddelflow' nodeset may see the light of day....

s

Nicholas O'Leary

unread,
Dec 8, 2016, 4:31:21 PM12/8/16
to Node-RED Mailing List
Hi Simon,

this is a not-entirely-ideal part of the current API.

Subflow definitions belong in the 'global' flow - not in individual flows.

To add a subflow you have to GET /flow/global, add your subflow to the 'subflows' array and PUT it back to /flow/global 
  

I'm not entirely happy with this current arrangement - needs some more thinking about.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/c572be48-8341-4b67-93e3-ac5f8d16c4d6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Simon H

unread,
Dec 9, 2016, 2:32:28 AM12/9/16
to Node-RED
Hi Nick,

I worked on some commercial software with a very similar concept (google 'mediamate'); and it's absolutely not easy :).  
We went with creating wrapped 'composites' which were within a 'flow', but exportable as a template.  So each instance of a running composite was unique and modifiable (e,g, even if two were in the same flow; each was unique), and did not affect other 'flows' where it had been used (basically, it was really only a visual representation; all the nodes existed in the 'flow' itself).

From the little I gleaned from the red source and testing, the 'subflows' get duplicated at runtime (e.g. context is not shared), so at runtime, it amounts to the same thing. 
And if you import a flow from library in the web editor which included a subflow, it creates a new subflow rather than using the original if still present (even if unchanged) 

Maybe in some future version of red we could consider an additional wrap type where the object is independent of global subflows.  One of the issues then is that it should only appear in the palette if exported or published ('copied' out at a specific moment), but should still be double-clickable to edit the content within a flow...

best,

Simon
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Simon H

unread,
Dec 9, 2016, 3:27:55 AM12/9/16
to Node-RED
Reply all
Reply to author
Forward
0 new messages