Skip to content

Design: subflows vNext

Nick O'Leary edited this page Jul 23, 2015 · 18 revisions

The existing subflow capability in node-red serves a purpose, but is need of further development to be truly useful.

The follow design outlines where we'll go next with subflows.

Definitions

There are three 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/n
  • loop-subflow : a subflow that defines a condition under which a message is iterated on. Inputs: 1, Outputs: 1
  • template-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.

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.

template-subflow

When editing a template-subflow, 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 edit dialog for an individual subflow-instance will then present a corresponding list of selected properties and allow the user to provide instance-specific values.

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.

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)

Lifecycle model

aka - how one thing can become another, and back again.

Notes:

  1. 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 become group nodes - and will create an inline-subflow
    • ungroup 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'
  2. 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.

Clone this wiki locally