Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "graph"

Index

Functions

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 ensureInputs

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

    Parameters

    • src: IObjectOf<ISubscribable<any>>

      -

    • inputIDs: string[] | undefined

      -

    • nodeID: string

      -

    Returns void

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 {@link @thi.ng/resolve-map#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 isNodeSpec

  • isNodeSpec(x: any): x is NodeSpec
  • Parameters

    • x: any

    Returns x is NodeSpec

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 {@link @thi.ng/rstream#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 {@link @thi.ng/rstream#StreamSync} for further reference.

    // TODO add close behavior opts

    Parameters

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

      -

    • Optional inputIDs: string[]

      -

    • Default value 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>

      -

    • Default value inputID: string = "src"

      -

    Returns NodeFactory<any>

Const node2

  • node2(xform: Transducer<IObjectOf<any>, any>, inputIDs?: Tuple<string, 2>, reset?: boolean): (src: NodeInputs, id: string) => ISubscribable<T>
  • 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>

      -

    • Default value inputIDs: Tuple<string, 2> = ["a", "b"]

      -

    • Default value reset: boolean = false

      -

    Returns (src: NodeInputs, id: string) => ISubscribable<T>

      • Parameters

        Returns ISubscribable<T>

Const nodeFromSpec

  • nodeFromSpec(state: IAtom<any>, spec: NodeSpec, id: string): (Anonymous function)
  • Transforms a single NodeSpec into a lookup function for {@link resolve} (which is called from initGraph). When that function is called, recursively resolves all specified input streams and calls this spec's fn to produce a new stream from these inputs.

    If the spec includes the optional outs keys, it also creates the subscriptions for each of the given output keys, which then can be used as inputs by other nodes. Each value in the outs subspec can be a function or state path (string/number/array, see {@link @thi.ng/paths# | @thi.ng/paths}). Functions are called with this node's constructed stream/subscribable and the output id and must return a new {@link @thi.ng/rstream#ISubscribable}. For path values a subscription is added to this node's result stream which then updates the provided state atom at the path given.

    Non-function output specs subs assume the raw node output value is an object from which the different output keys are being extracted. The special * output key can be used to handle the entire node output value. This is useful/required for non-object node result values.

    example
    out: {
      // fn output spec
      // creates new sub which uses {@link pick} transducer to
      // select key `a` from main node output (assumed to be object)
      a: (node, id) => node.subscribe({}, pick(id)),
    
      // yields sub of `b` key's values extracted from main output
      // and also stores them at given path in state atom
      b: "foo.b"
    
      // yields sub with same value as main node output and
      // stores vals in state atom at given path
      "*": "foo.main"
    }

    See api.ts for further details and possible spec variations.

    Parameters

    • state: IAtom<any>

      -

    • spec: NodeSpec

      -

    • id: string

      -

    Returns (Anonymous function)

Const prepareNodeInputs

  • prepareNodeInputs(ins: IObjectOf<NodeInputSpec>, state: IAtom<any>, resolve: ResolveFn): IObjectOf<ISubscribable<any>>
  • Parameters

    Returns IObjectOf<ISubscribable<any>>

Const prepareNodeOutputs

  • prepareNodeOutputs(outs: IObjectOf<NodeOutputSpec> | undefined, node: ISubscribable<any>, state: IAtom<any>, nodeID: string): IObjectOf<ISubscribable<any>>
  • Parameters

    • outs: IObjectOf<NodeOutputSpec> | undefined
    • node: ISubscribable<any>
    • state: IAtom<any>
    • nodeID: string

    Returns IObjectOf<ISubscribable<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

Generated using TypeDoc