A subflow is a collection of nodes that are collapsed into a single node in the workspace.
They can be used to reduce some visual complexity of a flow, or to package up a group of nodes as a reusable flow used in multiple places.
Once created, the subflow is added to the palette of available nodes. Individual instances of the subflow can then be added to the workspace just like any other node.
Note: a subflow cannot contain an instance of itself - either directly or indirectly.
A subflow can be created by selecting the ‘Subflow -> Create subflow’ option in the menu. This will create a blank subflow and open it in the workspace.
Reference | |
---|---|
Key shortcut | none |
Menu option | Subflows -> Create subflow |
Action | core:create-subflow |
It is also possible to convert the current selection of nodes to a subflow by selecting the ‘Subflow -> Selection to Subflow’ option in the menu. The nodes will be moved to a new subflow and replaced by a subflow instance node within the flow.
This is only possible if any wires coming into the selection are connected to one node - as the resulting subflow node can itself only have at most one input.
Reference | |
---|---|
Key shortcut | none |
Menu option | Subflows -> Selection to Subflow |
Action | core:convert-to-subflow |
There are two ways to open a subflow to edit its contents. Either double click its node in the palette, or click the ‘Edit flow template’ button in the edit dialog of a subflow instance node.
The subflow is opened in the workspace as a new tab. Unlike regular flow tabs, subflow tabs can be closed to hide them.
The inputs and outputs of the subflow are represented by the grey square nodes that can be wired into the flow as normal.
The toolbar provides options to add and remove these nodes. As with normal flows nodes, there can be at most one input and as many outputs as needed.
The toolbar provides an option to add a ‘status’ output to a subflow. This can be used to update the Status of subflow instance nodes.
The ‘edit properties’ button opens the subflow properties dialog. As with the Flow properties dialog, the name and description of the subflow can be set.
The ‘Properties’ tab of the edit dialog can be used to define a set of properties that can then be customised for each instance of the subflow. The properties are then exposed as environment variables within the subflow.
Each entry in the properties table can be expanded to customise how it is displayed when an instance of the subflow is edited. The ‘UI Preview’ tab provides a preview of how they will appear.
The Appearance tab provides options to:
The ‘delete subflow’ button in the subflow toolbar can be used to remove the subflow and all instances of it.
Node-RED: Low-code programming for event-driven applications.
A project of the OpenJS Foundation.