ollixx / node-red-contrib-components

reusable flows with a well defined api
MIT License
8 stars 9 forks source link
node-red

node-red-contrib-components

Components are an alternative approach to create reusable node-red flows and are very much inspired by action flows.

Components

Motivation

Some projects can get really complicated and having 20 tabs with hundreds of nodes needs some more structure. Components always have been in my head, despite subflows doing their job really well. But the later tend to be more cumbersome and less flexible. Action flows are another very nice approach to encapsulate (business) logic and make it reusable. But their definition of an API is not mine. So here it is: An advanced set of nodes, that will hopefully help you to organize your flows.

The Nodes

component_in - Start of a Component flow

Component input node

This input node is the starting point of an reusable flow. It allows to set a list of parameters, that it expects. Every parameter is defined by its name, a type and a flag to define it as required or optional. This list of parameters can be seen as the API of the component.

component_out - End of the flow

Component output node

This node returns the msg to the calling node and supports nested components.

If it receives a message, that is not created by a calling compontent node, the message is broadcast to all possible callers, i.e. all component nodes, that use the return node's flow.

A component flow can have more than one return node. For each of them, the calling component node optionally features a separate output port labeled with the name of the return node. By default, a return node will send its message to one "default" output port.

In versions to come, it will also allow to set some options like purging unwanted or temporary parts from the final msg.

component - the calling node

Component caller node

To use a prepared Component, this node is setup. It must be configured in accordance with the Component's parameter list, so that at least all required msg parts are connected to either of the known options also presented in the honorable change node:

Until now only required parameters are validated against null, undefined and empty string. More validation is one the todo list.

Install

node-red-contrib-components can be install using the node-red editor's pallete or by running npm in the console:

npm install node-red-contrib-components

Examples

There are some examples available now in the node-red specific way. Just select import... in the menu and find node-red-contrib-components in the exmaples sections. Beside some basic flows, that show how to use components, there are some more advanced scenarios to show speecific features like broadcast, in-only etc. Check it out.

Cut/Copy/Paste component nodes

At the moment only use comp can be copy/pasted wihtout problems. Cut/Copy/Pasting component flows, i.e. comp start and comp return nodes together with any linked use comp nodes will not preserve the association between them. There is a work around to move (not copy) components together with their use comp nodes: Export the set of nodes, remove them from NR and re-import them at the new tab. At least the Cut/Paste behaviour will probably be fixed in one of the next releases.

Component features in detail

Ideas