gradum-kit - v0.1.0
    Preparing search index...

    Class GradumConstrainer<ElementType, ViewType, ModelType, EmitterType>

    GradumConstrainer

    Keeps a set of objects satisfying a constraint. Attach one to an element and it watches a list of objects, and whenever a trigger object is interacted with it runs the solvers declared with @solver until the constraint holds again — capped by maxPasses so propagation cannot cycle forever. Checkers (@checker) report whether the constraint already holds; mutators (@mutator) adjust values as part of resolving.

    Type Parameters

    Hierarchy (View Summary)

    Index
    keyName: string

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

    constrainerName: string

    The name of the constrainer.

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

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

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

    priority: number

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

    objectList: GradumNodeList

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

    triggerList: GradumNodeList

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

    defaultQueue: GradumQueue<object> | object[]

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

    maxPasses: number

    The maximum number of passes allowed per object for this constrainer 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.

    • get active(): boolean

      Returns boolean

      Whether the constrainer 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 constrainer's object list.

    • get queue(): GradumQueue<object>

      Returns GradumQueue<object>

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

    • Function

      initialize

      Returns void

      Initialization function that calls GradumSelector.makeConstrainer 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 constrainer.

    • 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 constrainer. 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, allowing for method chaining.

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

    • Function

      addChecker

      Parameters

      • properties: ConstrainerAddCallbackProperties<ConstrainerChecker>

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

      Returns this

      Itself, allowing for method chaining.

      Register a checker in the constrainer. 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, allowing for method chaining.

      Remove a checker from this constrainer by its name.

    • Function

      clearCheckers

      Returns this

      Itself, allowing for method chaining.

      Remove all checkers attached to this constrainer.

    • Function

      check

      Parameters

      Returns boolean

      Whether the constrainer passes all checks.

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

    • Function

      addMutator

      Parameters

      Returns this

      Itself, allowing for method chaining.

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

    • Function

      removeMutator

      Parameters

      • name: string

        The mutator name.

      Returns this

      Itself, allowing for method chaining.

      Remove a mutator from this constrainer by its name.

    • Function

      clearMutators

      Returns this

      Itself, allowing for method chaining.

      Remove all mutators attached to this constrainer.

    • Function

      mutate

      Type Parameters

      • Type = any

        The type of the value to mutate

      Parameters

      Returns Type

      The mutated result.

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

    • Function

      addSolver

      Parameters

      Returns this

      Itself, allowing for method chaining.

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

    • Function

      removeSolver

      Parameters

      • name: string

        The solver's name.

      Returns this

      Itself, allowing for method chaining.

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

    • Function

      clearSolvers

      Returns this

      Itself, allowing for method chaining.

      Remove all solvers attached to the constrainer.

    • Function

      solve

      Parameters

      Returns this

      Itself, allowing for method chaining.

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

    • Function

      onActivate

      Returns void

      Function to execute when the constrainer is activated.

    • Function

      onDeactivate

      Returns void

      Function to execute when the constrainer 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.