turbodombuilder - v0.9.66
    Preparing search index...

    Class TurboEnforcer<ElementType, ViewType, ModelType, EmitterType>

    TurboEnforcer

    Class representing an enforcer in MVC, bound to the provided element.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    keyName: string

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

    enforcerName: string

    The name of the enforcer.

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

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

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

    priority: number

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

    objectList: TurboNodeList

    The list of objects constrained by the enforcer. To manipulate, check TurboNodeList. Defaults to the children of the element the enforcer is attached to.

    triggerList: TurboNodeList

    The list of objects that trigger the enforcer to resolve. Interacting with any of these objects would typically lead to the solving of the given enforcer. To manipulate, check TurboNodeList. Defaults to the objects in this.objectList.

    defaultQueue: TurboQueue<object> | object[]

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

    maxPasses: number

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

    element: ElementType

    The element it is bound to.

    view: ViewType

    The MVC view.

    model: ModelType

    The MVC model.

    emitter: EmitterType

    The MVC emitter.

    Accessors

    • get active(): boolean

      Returns boolean

      Whether the enforcer is active. Defaults to true.

    • set active(value: boolean): void

      Parameters

      • value: boolean

      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 enforcer's object list.

    • get queue(): TurboQueue<object>

      Returns TurboQueue<object>

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

    Methods

    • Function

      initialize

      Returns void

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

    • 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 enforcer.

    • 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 enforcer. 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 enforcer. It is reset on every new resolving session.

    • Function

      addChecker

      Parameters

      • properties: EnforcerAddCallbackProperties<EnforcerChecker>

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

      Returns this

      • Itself for chaining.

      Register a checker in the enforcer. 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 enforcer by its name.

    • Function

      clearCheckers

      Returns this

      • Itself for chaining.

      Remove all checkers attached to this enforcer.

    • Function

      check

      Parameters

      Returns boolean

      • Whether the enforcer passes all checks.

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

    • Function

      addMutator

      Parameters

      Returns this

      • Itself for chaining.

      Register a mutator in the enforcer. 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 enforcer by its name.

    • Function

      clearMutators

      Returns this

      • Itself for chaining.

      Remove all mutators attached to this enforcer.

    • Function

      mutate

      Type Parameters

      • Type = any

        The type of the value to mutate

      Parameters

      Returns Type

      • The mutated result.

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

    • Function

      addSolver

      Parameters

      Returns this

      • Itself for chaining.

      Register a solver in the enforcer. Solvers typically execute after an event is fired to ensure the enforcer's constraints are maintained. They process all objects in the enforcer'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 enforcer's list of solvers.

    • Function

      clearSolvers

      Returns this

      • Itself for chaining.

      Remove all solvers attached to the enforcer.

    • Function

      solve

      Parameters

      Returns this

      • Itself for chaining.

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

    • Function

      onActivate

      Returns void

      Function to execute when the enforcer is activated.

    • Function

      onDeactivate

      Returns void

      Function to execute when the enforcer is deactivated.

    • 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.