Class Callbacks<Types, Ctx>

Typed event registry with support for one-time listeners, protected listeners, and delayed execution.

Used internally by Module and all components, but can also be instantiated on its own.

Type Parameters

Hierarchy

  • Destroyable
    • Callbacks

Constructors

Accessors

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get list(): ICallback<Types, Ctx>[]

    Snapshot of all registered callbacks.

    Useful for debugging; do not mutate the returned array.

    Returns ICallback<Types, Ctx>[]

Methods

  • Clears all registered callbacks.

    Returns void

  • Registers a callback and returns its id plus a removal function.

    Prefer on when you only need the destructor.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    Returns { id: string; remove: () => boolean }

  • 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

  • Invokes all listeners registered for the given event.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • target: T

      Event name.

    • arg: Types[T]

      Payload passed as the first argument to each listener.

    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

  • Removes a callback by id.

    Protected callbacks are skipped unless they are cleared internally (for example on destroy).

    Parameters

    • id: string

    Returns boolean