Skip to content

createNode()

Dan Stocker edited this page May 30, 2019 · 1 revision

Usage: createNode(outFields, createInPorts)

Module: flowcode

Creates an ad-hoc node with the specified output and input ports. As output ports are merely slots for external input ports, only their names are required.

The second parameter receives one argument: outputs. This is a lookup of functions prepared by createNode(), indexed by output port names, which can be used for emitting on the node's output ports. createInPorts() is expected to return a lookup of functions, indexed by input port names, which will serve as input ports for the created node.

Both input and output functions take two arguments:

  • value, which is the value being received / emitted by the node, and
  • tag, which identifies the impulse throughout the graph.

createNode() returns a Node object, with at least two properties:

  • i, a collection of functions that serve as the node's input ports
  • o, a collection of structures that serve as output ports (the specifics of these structures are not relevant to their usage)
import {connect, createNode} from "flowcode";
type In = {d_in: number};
type Out = {d_out: number};
const node = createNode<In, Out>(["d_out"], (outputs) => ({
  d_in: (value, tag) => outputs.d_out(value, tag)
}));
connect(node.o.d_out, console.log);
node.i.d_in("Hello World!");
// logs "Hello World!"
Clone this wiki locally