This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
The existing subflow capability in node-red serves a purpose, but is in need of further development to be truly useful.
The follow design outlines where we'll go next with subflows.
Definitions
There are four types of subflow:
inline-subflow
: a subflow that is defined and used once within a single flow. It is not reusable. Inputs: 0/1, Outputs: 0/nloop-subflow
: a subflow that defines a condition under which a message is iterated on. Inputs: 1, Outputs: 1template-subflow
: a subflow that is added to the palette as a reusable set of nodes. This is equivalent to what we have today. Inputs: 0/1, Outputs: 0/n. It defines a set of properties of its nodes that can be customised by individual instances.subflow-instance
: an instance of a template-subflow that appears in a flow
inline-subflow
A new subflow
node is available in the function
section of the palette. This can be dragged onto the workspace to create an inline-subflow
. It defaults to 1-input/1-output as we expect subflows to most commonly be used mid-flow.
An option exists in the subflow toolbar to add it to the palette. This will extract the subflow definition, and substitute a subflow-instance node in its place.
The edit properties
button presents a list of all nodes in the subflow. The user can then pick which node's status should be exposed by the subflow node.
template-subflow
When editing a template-subflow, in addition to configuring what status to expose, the edit properties
button presents a list of all nodes in the subflow and their configurable properties. This will be limited to properties the editor is able to identify as being string/boolean/number/config node types - Object/Array types won’t be available. The user can then select which properties should be exposed to subflow instances. The current proposal only extends this as far as 'real' nodes - not config nodes. This is because config nodes exist at the top level - subflows don't get their own copies of config nodes. Some more thought is needed to see how they could be included here.
The remove from palette
button does just that. If there is one instance of the subflow, it is automatically converted to an inline-subflow. If there are more than one, a dialog is shown to ask the user whether to convert each to an inline-subflow, or to delete all instances.
The edit dialog for the node will also provide a list of nodes within the subflow for the user to pick which, if any, should surface their status messages to the subflow instance node.
subflow-instance
Added to a flow by dragging on a template-subflow from the subflow category in the palette.
Double-clicking on the subflow-instance opens its edit dialog. This dialog will:
- allow the instance name to be set,
- allow the properties the template-subflow exposes to be customised,
- provide a button to 'break the link' to the template-subflow. When clicked, the instance will become an inline-subflow.
loop-subflow
A new loop
node is available in the function
section of the palette. This can be dragged on to the workspace to create a loop-subflow. (node colour/icon tbd)
It is fixed to 1-input and 1-output - this cannot be changed.
The loop condition is configurable in the toolbar (quick ui mock-up - need to test if there’s enough room to do it in the toolbar directly, or via some other means).
When a message arrives on the input, the loop condition is evaluated to see if the loop should continue. If so, it passes through the flow defined in the loop. When the message reaches the output of the subflow, the loop condition is evaluated, and so on.
(Need to determine the proper conditions - foreach/while/until/do-loop - and message semantics)
Lifecycle model
aka - how one thing can become another, and back again.
Notes:
-
The existing subflow menu options will change.
Create subflow
will be removed - dragging a subflow node will be the primary way of creating a blank subflow.Selection to subflow
will becomegroup nodes
- and will create an inline-subflowungroup nodes
will be added - and will remove a inline-subflow and reinsert its content in the flow.- need to test the terms 'group' and 'ungroup'
-
Whilst it is possible to convert inline-subflow to template-subflow and back, it is not possible to convert to/from a loop subflow.
Import/Export & Copy/Paste
As inline-subflows and loop-subflows only exist in the context of a single flow, they behave like any other node when copied/pasted/exported/imported.
When a subflow-instance node is exported, its corresponding template-subflow will automatically get included in the export.
When it is imported, it will examine all existing template-subflows to see if an identical one exists. If it does exist, it avoids adding a duplicate.
A mechanism will be provided (either via toolbar or menu) to export a template-subflow without requiring an instance in the workspace as you do today.