@wpazderski/js-utils
    Preparing search index...

    Collection of callbacks that can be added, removed and called.

    Type Parameters

    • T extends (...args: any[]) => any

      Type of the callback function.

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    callbacks: T[] = []

    Array of callbacks.

    name: undefined | CallbacksName

    Name of the Callbacks instance. This is used for debugging and error reporting.

    Methods

    • Adds a callback to the collection. If the callback is already present, it will not be added again.

      Parameters

      • callback: T

        The callback function to add.

      Returns void

    • Calls all callbacks in the collection with the provided arguments. If any callback throws an error, it will be collected and thrown as a CallbackError after all callbacks have been called.

      Parameters

      • ...args: Parameters<T>

        Arguments to pass to the callbacks.

      Returns void

      CallbackError If any callback throws an error, a CallbackError will be thrown containing all errors. The CallbackError will include the name of the Callbacks instance if it was provided.

    • Removes a callback from the collection. If the callback is not present, it will do nothing.

      Parameters

      • callback: T

        The callback function to remove.

      Returns void