-
Notifications
You must be signed in to change notification settings - Fork 1
Custom Nodes
Dan Stocker edited this page May 30, 2019
·
1 revision
Nodes are rarely created by invoking createNode() directly, as one would have to supply types (for TypeScript), output port names, and the function createInPorts() on each call. Instead, createNode() usually gets wrapped
inside a factory function which has these already bundled.
import {createNode, Node} from "flowcode";
type In<T> = {d_in: T};
type Out<T> = {d_out: T};
type Forwarder<T> = Node<In, Out>;
function createForwarder<T>(): Forwarder<T> {
return createNode<In, Out>(["d_out"], (outputs) => ({
d_in: (value, tag) => outputs.d_out(value, tag)
}));
}