Reference - BaklavaJS
    Preparing search index...

    Class ForwardEngine<CalculationData>

    Type Parameters

    • CalculationData = any

    Hierarchy (View Summary)

    • BaseEngine<
          CalculationData,
          [
              startingNode: AbstractNode,
              nodeUpdateEvent: INodeUpdateEventData
              | undefined,
          ],
      >
      • ForwardEngine
    Index

    Constructors

    Properties

    editor: Editor
    events: {
        afterNodeCalculation: BaklavaEvent<
            AfterNodeCalculationEventData,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
        >;
        afterRun: BaklavaEvent<
            CalculationResult,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
        >;
        beforeNodeCalculation: BaklavaEvent<
            BeforeNodeCalculationEventData,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
        >;
        beforeRun: PreventableBaklavaEvent<
            CalculationData,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
        >;
        statusChange: BaklavaEvent<
            EngineStatus,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
        >;
    } = ...

    Type Declaration

    • afterNodeCalculation: BaklavaEvent<
          AfterNodeCalculationEventData,
          BaseEngine<
              CalculationData,
              [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
          >,
      >

      This event is called after a node has been calculated.

    • afterRun: BaklavaEvent<
          CalculationResult,
          BaseEngine<
              CalculationData,
              [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
          >,
      >

      This event is called as soon as a run is completed. The argument is the result of the calculation.

    • beforeNodeCalculation: BaklavaEvent<
          BeforeNodeCalculationEventData,
          BaseEngine<
              CalculationData,
              [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
          >,
      >

      This event is called before a node is calculated. It is not preventable since this would break calculation.

    • beforeRun: PreventableBaklavaEvent<
          CalculationData,
          BaseEngine<
              CalculationData,
              [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
          >,
      >

      This event will be called before all the nodes calculate functions are called. The argument is the calculationData that the nodes will receive

    • statusChange: BaklavaEvent<
          EngineStatus,
          BaseEngine<
              CalculationData,
              [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
          >,
      >
    hooks: {
        gatherCalculationData: SequentialHook<
            CalculationData
            | undefined,
            BaseEngine<
                CalculationData,
                [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData],
            >,
            CalculationData,
        >;
        transferData: DynamicSequentialHook<any, IConnection, any>;
    } = ...
    recalculateOrder: boolean = true

    Accessors

    Methods

    • Force the engine to recalculate the node execution order before the next run. This is normally done automatically. Use this method if the default change detection does not work in your scenario.

      Returns void

    • Use the gatherCalculationData hook to get the calculation data

      Parameters

      • ...args: [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData]

        The calculation arguments with which the engine's calculate method will be called (in addition to the calculationData)

      Returns Promise<CalculationResult | null>

      The calculation result

    • Check whether a connection can be created. A connection can not be created when it would result in a cyclic graph.

      Parameters

      • from: NodeInterface

        The interface from which the connection would start

      • to: NodeInterface

        The interface where the connection would end

      Returns { connectionAllowed: boolean; connectionsInDanger: Connection[] }

      Whether the connection can be created

    • Overwrite this method to perform the calculation

      Parameters

      • calculationData: CalculationData

        The data which is provided to each node's calculate method

      • startingNode: AbstractNode
      • data: INodeUpdateEventData | undefined

      Returns Promise<CalculationResult>

      The calculation result

    • This method is called whenever the graph or values of node interfaces have been changed. You can overwrite this method to automatically trigger a calculation on change. Note: This method is only called when the engine is either idle or running.

      Parameters

      • recalculateOrder: boolean

        Whether the change modified the graph itself, e. g. a connection or a node was added/removed

      • OptionalupdatedNode: AbstractNode

        If a node was updated (which means the value a node's interface has been changed): the node that was updated; undefined otherwise

      • Optionaldata: INodeUpdateEventData

        If a node was updated: The update event payload to determine, which interface exactly has been changed; undefined otherwise

      Returns void

    • Run a non-root graph. This method can be used by nodes to calculate internal graphs (e. g. GraphNode). DO NOT use this method for calculation of the root graph! It won't emit any events.

      Parameters

      • graph: Graph

        The graph to execute

      • inputs: Map<string, any>

        Map<NodeInterfaceId, value>

      • calculationData: CalculationData

        The data which is provided to each node's calculate method

      Returns Promise<CalculationResult>

      A promise that resolves to a map that maps rootNodes to their calculated value (what the calculation function of the node returned)

    • Calculate all nodes once. This will automatically calculate the node calculation order if necessary and transfer values between connected node interfaces.

      Parameters

      • calculationData: CalculationData

        The data which is provided to each node's calculate method

      • ...args: [startingNode: AbstractNode, nodeUpdateEvent: INodeUpdateEventData]

      Returns Promise<CalculationResult | null>

      A promise that resolves to either

      • a map from each node's id to its calculated value (what the calculation function of the node returned)
      • null if the calculation was prevented from the beforeRun event
    • Validate the result of a node's calculate method. A result is valid if:

      • is has the correct format (it must be an object, where the key is the interface key and the value is the output value for that interface)
      • every output interface has a value assigned to it (null and undefined are also valid, but the key must exist in the object)

      Parameters

      • node: AbstractNode

        The node which produced the output data

      • output: any

        The result of the node's calculate method

      Returns void