-
Notifications
You must be signed in to change notification settings - Fork 1
Key Concepts
FlowCode is a dataflow programming paradigm. A FlowCode program consists of nodes and connections. Nodes expose functions for inputs, and function slots for outputs. Data flows between nodes - unidirectionally - through the connections between outputs and inputs (ports).
FlowCode programs may be edited graphically, or as text.
The node is the functional unit of a FlowCode program. It
- receives input through functions exposed as input ports,
- processes input, and
- emits results through output ports.
Nodes can be either atomic or composite. Atomic nodes are implemented with textual code. Composite nodes have an internal structure of made up of connected nodes, with ports of those nodes exposed as the composite node's own ports. (Both input / output.)
Similar to classes in OOP, nodes can be created based on a blueprint (type). Unlike OOP however, there is no inheritance between nodes. Node functionality is re-used by including the corresponding node in a composite node.
The port is the part of the node through which it communicates. They fall into two categories: input and output.
Input ports are plain functions, created when creating the node. Output ports are sets of functions populated on connection.
Connections are established by assigning input ports to output ports. FlowCode allows any number of incoming and outgoing connections from / to a given port.
Neither input nor output ports may be removed or replaced once the node is created.
As input ports are plain JavaScript functions, they can be passed around as such. Also, plain JavaScript functions that are not input ports, like
console.log, may be connected to outputs ports.
FlowCode programs are built by establishing connections between nodes. Whenever a node invokes one of its output ports with certain arguments, all connected input ports will be invoked with the same arguments.
Connections may be established and destroyed at runtime, though most FlowCode programs are static graphs.
import {connect} from "flowcode";
connect(node1.o.d_val, node2.i.d_val);A set of FlowCode nodes, where a path exists (regardless of direction) between any two nodes, is called a program.
The impulse is the unit of input to the program in time domain. Impulses usually ripple through a significant portion of the program.
A stream is a series of impulses.
Tags identify impulses in a FlowCode program, and they are specified via the second argument of port functions.
// sending directly to an input port:
node.i.d_val("foo", "1");
// or when emitting from a createNode() callback:
outputs.d_val("foo", "1");Because of this, custom nodes are responsible for specifying a tag on emit. Tags in these cases are either preserved as received, or changed according to some rule.
Tags are mostly used for tracking and synchronizing impulses.
It's good practice to always supply a tag, even when the application does not require it at the moment.