Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/rstream-graph

Index

Type aliases

Graph

Graph: IObjectOf<Node>

GraphSpec

GraphSpec: IObjectOf<NodeSpec | Node | NodeResolver>

A dataflow graph spec is simply an object where keys are node names and their values are NodeSpecs, defining a node's inputs, outputs and the operation to be applied to produce one or more result streams.

NodeFactory

NodeFactory<T>: (src: NodeInputs, id: string) => ISubscription<T, any>

A function which constructs and returns an ISubscribable using given object of inputs and node ID. See node() and node1().

Type parameters

  • T

Type declaration

    • (src: NodeInputs, id: string): ISubscription<T, any>
    • Parameters

      Returns ISubscription<T, any>

NodeInputs

NodeInputs: IObjectOf<ISubscription<any, any>>

NodeOutputFn

NodeOutputFn: (node: ISubscription<any, any>, id: NumOrString) => ISubscription<any, any>

Type declaration

    • (node: ISubscription<any, any>, id: NumOrString): ISubscription<any, any>
    • Parameters

      • node: ISubscription<any, any>
      • id: NumOrString

      Returns ISubscription<any, any>

NodeOutputSpec

NodeOutputSpec: Path | NodeOutputFn

NodeOutputs

NodeOutputs: IObjectOf<ISubscription<any, any>>

NodeResolver

NodeResolver: Fn<ResolveFn, Node>

Functions

Const add

  • add(src: NodeInputs, id: string): ISubscription<number, any>

Const addNode

  • Compiles given NodeSpec and adds it to graph. Returns compiled Node object for the given spec. Throws error if the graph already contains a node with given id.

    Parameters

    Returns Node

Const div

  • div(src: NodeInputs, id: string): ISubscription<number, any>

Const ensureInputs

  • ensureInputs(src: IObjectOf<ISubscription<any, any>>, inputIDs: undefined | string[], nodeID: string): void
  • Helper function to verify given object of inputs has required input IDs. Throws error if validation fails.

    Parameters

    • src: IObjectOf<ISubscription<any, any>>

      -

    • inputIDs: undefined | string[]

      -

    • nodeID: string

      -

    Returns void

Const extract

  • extract(path: readonly NumOrString[] | NumOrString, inputID?: string): NodeFactory<any>
  • Nested value extraction node. Higher order function.

    Inputs: 1

    Parameters

    • path: readonly NumOrString[] | NumOrString

      value lookup path

    • Optional inputID: string

      default: src

    Returns NodeFactory<any>

Const initGraph

  • Dataflow graph initialization function. Takes a state Atom (or null if not needed) and an object of NodeSpec values or functions returning Node objects. Calls nodeFromSpec() for each spec and then recursively resolves references via resolve. Returns new initialized graph object of Node objects and {@link @thi.ng/rstream# | @thi.ng/rstream} stream constructs. Does NOT mutate original GraphSpec object.

    Parameters

    Returns Graph

Const mul

  • mul(src: NodeInputs, id: string): ISubscription<number, any>

Const node

  • node(xform: Transducer<IObjectOf<any>, any>, inputIDs?: string[], reset?: boolean): NodeFactory<any>
  • Higher order node / stream creator. Takes a transducer and (optional) required input stream IDs. The returned function takes an object of input streams and returns a new StreamSync instance. The returned function will throw an error if inputIDs is given and the object of inputs does not contain all of them.

    If reset is true (default: false), the xform will only re-run when all inputs have produced new values. See StreamSync for further reference.

    // TODO add close behavior opts

    Parameters

    • xform: Transducer<IObjectOf<any>, any>

      -

    • Optional inputIDs: string[]

      -

    • reset: boolean = false

      -

    Returns NodeFactory<any>

Const node1

  • node1(xform?: Transducer<any, any>, inputID?: string): NodeFactory<any>
  • Similar to node, but optimized for nodes using only a single input. Uses "src" as default input ID.

    // TODO add close behavior opts

    Parameters

    • Optional xform: Transducer<any, any>

      -

    • inputID: string = "src"

      -

    Returns NodeFactory<any>

Const node2

  • node2(xform: Transducer<IObjectOf<any>, any>, inputIDs?: Tuple<string, 2>, reset?: boolean): NodeFactory<any>
  • Syntax sugar for node(), intended for nodes w/ 2 inputs, by default named a & b (but can be overridden).

    Parameters

    • xform: Transducer<IObjectOf<any>, any>

      -

    • inputIDs: Tuple<string, 2> = ...

      -

    • reset: boolean = false

      -

    Returns NodeFactory<any>

Const removeNode

  • removeNode(graph: Graph, id: string): boolean
  • Calls .unsubscribe() on given node and all of its outputs, then removes it from graph. Returns false if no node exists for given id.

    Parameters

    Returns boolean

Const stop

  • Calls .unsubscribe() on all nodes in the graph, causing all related streams & subscriptions to terminate.

    Parameters

    Returns void

Const sub

  • sub(src: NodeInputs, id: string): ISubscription<number, any>

Generated using TypeDoc