Class Module<CallbacksMap, StaticProps, MutableProps>

A base class for modules that handle responsive properties, event listeners, and custom callbacks.

Type Parameters

Hierarchy (View Summary)

Constructors

Accessors

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

Methods

  • Adds prefixed classes to an element and removes them on destroy.

    Skips classes that are already present on the element.

    Parameters

    • element: Element

      Target DOM element.

    • ...classes: string[]

      Unprefixed class name segments.

    Returns void

  • Builds one or more prefixed class names.

    Parameters

    • ...classes: string[]

      Unprefixed class name segments.

    Returns string

    Space-separated prefixed class string.

  • Internal method to handle the destruction of the module. It removes all callbacks, destroys properties, and cleans up event listeners and class names.

    Returns void

  • Emits a callback event with a fixed payload.

    Type Parameters

    • E extends string | number | symbol

    Parameters

    Returns void

  • Set default mutable props

    Returns TRequiredProps<MutableProps>

  • Get default static props

    Returns TRequiredProps<StaticProps>

  • Method that is called when the module's properties mutate. In most cases, used to handle callbacks.

    Parameters

    Returns void

  • Destroys the instance and runs all registered cleanup actions.

    Safe to call multiple times; subsequent calls are ignored.

    Execution order:

    1. _destroy
    2. all onDestroy callbacks, in registration order
    3. isDestroyed is set to true

    Returns void

  • Registers a function to run when the instance is destroyed.

    If the instance is already destroyed, action runs immediately.

    Parameters

    • action: () => void

      Cleanup function (for example remove listeners or DOM classes).

    Returns void

  • Change module's mutable properties

    Parameters

    Returns void