turbodombuilder - v0.9.48
    Preparing search index...

    Class TurboSubstrate<ElementType, ViewType, ModelType, EmitterType>

    TurboSubstrate

    Class representing a substrate in MVC, bound to the provided element.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    • Type Parameters

      • ElementType extends object = object

        The type of the element.

      • ViewType extends TurboView<
            object,
            TurboModel<
                any,
                any,
                any,
                "map"
                | "array",
                TurboDataBlock<any, any, any, any, any>,
            >,
            TurboEmitter<
                TurboModel<
                    any,
                    any,
                    any,
                    "map"
                    | "array",
                    TurboDataBlock<any, any, any, any, any>,
                >,
            >,
        > = TurboView<
            any,
            any,
            TurboEmitter<
                TurboModel<
                    any,
                    any,
                    any,
                    "map"
                    | "array",
                    TurboDataBlock<any, any, any, any, any>,
                >,
            >,
        >

        The element's view type, if any.

      • ModelType extends TurboModel<
            any,
            any,
            any,
            "map"
            | "array",
            TurboDataBlock<any, any, any, any, any>,
        > = TurboModel<
            any,
            any,
            any,
            "map"
            | "array",
            TurboDataBlock<any, any, any, any, any>,
        >

        The element's model type, if any.

      • EmitterType extends TurboEmitter<
            TurboModel<
                any,
                any,
                any,
                "map"
                | "array",
                TurboDataBlock<any, any, any, any, any>,
            >,
        > = TurboEmitter<
            TurboModel<
                any,
                any,
                any,
                "map"
                | "array",
                TurboDataBlock<any, any, any, any, any>,
            >,
        >

        The element's emitter type, if any.

      Returns TurboSubstrate<ElementType, ViewType, ModelType, EmitterType>

    Properties

    element: ElementType

    The element it is bound to.

    view: ViewType

    The MVC view.

    model: ModelType

    The MVC model.

    emitter: EmitterType

    The MVC emitter.

    keyName: string

    The key of the substrate. Used to retrieve it in the main component. If not set, if the element's class name is MyElement and the substrate's class name is MyElementSomethingSubstrate, the key would default to "something".

    substrateName: string

    The name of the substrate.

    The property keys of the substrate solvers defined in the instance.

    The property keys of the substrate checkers defined in the instance.

    The property keys of the substrate mutators defined in the instance.

    priority: number

    The priority of the substrate. Higher priority substrates (lower number) should be resolved first. Defaults to 10.

    defaultQueue: TurboQueue<object> | object[]

    The default queue template for the substrate, used when starting a new resolving pass. It defaults to the substrate's object list.

    maxPasses: number

    The maximum number of passes allowed per object for this substrate during resolving. This helps prevent infinite cycles in constraint propagation. Defaults to 5.

    Accessors

    • get active(): boolean

      Returns boolean

      Whether the substrate is active. Defaults to true.

    • set active(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get objectList(): Set<object>

      Returns Set<object>

      The list of objects constrained by the substrate. Retrieving it will return a shallow copy as a Set. Use addObject and removeObject to manipulate the list.

    • set objectList(value: Set<object> | HTMLCollection | NodeList): void

      Parameters

      Returns void

    • get onObjectListChange(): Delegate<
          (object: object, status: "added" | "removed") => void,
      >

      Returns Delegate<(object: object, status: "added" | "removed") => void>

      Delegate fired whenever an object is added to or removed from the substrate's object list.

    • get queue(): TurboQueue<object>

      Returns TurboQueue<object>

      The current queue to be processed by the substrate while resolving.

    Methods

    • Protected Function

      setup

      Returns void

      Called in the constructor. Use for setup that should happen at instantiation, before this.initialize() is called.

    • Protected Function

      setupUIListeners

      Returns void

      Setup method for defining DOM and input event listeners.

    • Protected Function

      setupChangedCallbacks

      Returns void

      Setup method intended to initialize change listeners and callbacks.

    • Function

      initialize

      Returns void

      Initialization function that calls makeSubstrate on this.element, sets it up, and attaches all the defined solvers.

    • Function

      addObject

      Parameters

      • object: object

        The object to add.

      Returns this

      Adds the provided object to the substrate's list.

    • Function

      removeObject

      Parameters

      • object: object

        The object to remove.

      Returns this

      Removes the provided object from the substrate's list.

    • Function

      hasObject

      Parameters

      • object: object

        The object to check.

      Returns boolean

      • Whether the object is present.

      Whether the provided object is included in the substrate's list.

    • Function

      getObjectPasses

      Parameters

      • object: object

        The object to query.

      Returns number

      • Number of passes already performed on this object.

      Retrieve how many times the given object has been processed for the current resolving session of the substrate.

    • Function

      getObjectData

      Parameters

      • object: object

        The object to query.

      Returns Record<string, any>

      • The stored data object (or an empty object if none).

      Retrieve custom per-object data for this substrate. It is reset on every new resolving session.

    • Function

      setObjectData

      Parameters

      • object: object

        The object to update.

      • Optionaldata: Record<string, any>

        The new data object to associate with this object.

      Returns this

      • Itself for chaining.

      Set custom per-object data for this substrate. It is reset on every new resolving session.

    • Function

      addChecker

      Parameters

      • properties: SubstrateAddCallbackProperties<SubstrateChecker>

        Configuration object, including the checker callback to be executed, the name of the checker to access it later, the name of the attached substrate, and the priority of the checker.

      Returns this

      • Itself for chaining.

      Register a checker in the substrate. Checkers dictate whether the event should continue executing depending on the provided context (event, tool, target, etc.).

    • Function

      removeChecker

      Parameters

      • name: string

        The checker name.

      Returns this

      • Itself for chaining.

      Remove a checker from this substrate by its name.

    • Function

      clearCheckers

      Returns this

      • Itself for chaining.

      Remove all checkers attached to this substrate.

    • Function

      check

      Parameters

      Returns boolean

      • Whether the substrate passes all checks.

      Evaluate all checkers for this substrate and return whether the event should proceed or halt.

    • Function

      addMutator

      Parameters

      Returns this

      • Itself for chaining.

      Register a mutator in the substrate. Mutators compute or transform a value based on the context.

    • Function

      removeMutator

      Parameters

      • name: string

        The mutator name.

      Returns this

      • Itself for chaining.

      Remove a mutator from this substrate by its name.

    • Function

      clearMutators

      Returns this

      • Itself for chaining.

      Remove all mutators attached to this substrate.

    • Function

      mutate

      Type Parameters

      • Type = any

        The type of the value to mutate

      Parameters

      Returns Type

      • The mutated result.

      Execute a mutator for this substrate and return the resulting value.

    • Function

      addSolver

      Parameters

      Returns this

      • Itself for chaining.

      Register a solver in the substrate. Solvers typically execute after an event is fired to ensure the substrate's constraints are maintained. They process all objects in the substrate's queue, one after the other.

    • Function

      removeSolver

      Parameters

      • name: string

        The solver's name.

      Returns this

      • Itself for chaining.

      Remove the given function from the substrate's list of solvers.

    • Function

      clearSolvers

      Returns this

      • Itself for chaining.

      Remove all solvers attached to the substrate.

    • Function

      solveSubstrate

      Parameters

      Returns this

      • Itself for chaining.

      Solve the substrate by executing all of its attached solvers. Each solver will be executed on every object in the substrate's queue, incrementing its number of passes in the process.

    • Function

      onActivate

      Returns void

      Function to execute when the substrate is activated.

    • Function

      onDeactivate

      Returns void

      Function to execute when the substrate is deactivated.