Reference - BaklavaJS
    Preparing search index...

    Class BaseEngine<CalculationData, CalculationArgs>Abstract

    Type Parameters

    • CalculationData
    • CalculationArgs extends any[]

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    editor: Editor
    events: {
        afterNodeCalculation: BaklavaEvent<
            AfterNodeCalculationEventData,
            BaseEngine<CalculationData, CalculationArgs>,
        >;
        afterRun: BaklavaEvent<
            CalculationResult,
            BaseEngine<CalculationData, CalculationArgs>,
        >;
        beforeNodeCalculation: BaklavaEvent<
            BeforeNodeCalculationEventData,
            BaseEngine<CalculationData, CalculationArgs>,
        >;
        beforeRun: PreventableBaklavaEvent<
            CalculationData,
            BaseEngine<CalculationData, CalculationArgs>,
        >;
        statusChange: BaklavaEvent<
            EngineStatus,
            BaseEngine<CalculationData, CalculationArgs>,
        >;
    } = ...

    Type declaration

    hooks: {
        gatherCalculationData: SequentialHook<
            undefined
            | CalculationData,
            BaseEngine<CalculationData, CalculationArgs>,
            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: CalculationArgs

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

      Returns Promise<null | CalculationResult>

      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 CheckConnectionHookResult

      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

      • ...calculationArgs: CalculationArgs

        Additional data which is only provided to the engine

      Returns Promise<CalculationResult>

      The calculation result

    • Gathers the values of all unconnected input interfaces in the graph

      Parameters

      • graph: Graph

      Returns Map<string, any>

      Map nodeInterface.id -> value

    • 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

    • Temporarily pause the engine. Use this method when you want to update the graph with the calculation results.

      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

      Returns Promise<null | CalculationResult>

      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
    • Start the engine. After started, it will run everytime the graph is changed.

      Returns void

    • 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