Class CallbackEmitter<T>

Simple class to handle callbacks.

T Event map for the listeners as object with event name and the type of the arguments in the callback.

type EventMap = {
test: number;
}
class SomeEmitter extends CallbackEmitter<EventMap> {}

const emitter = new SomeEmitter();
emitter.addListener('test', (e, test) => {
// e is instance of the emitter
// test is number
})

Type Parameters

Hierarchy (view full)

Constructors

Methods

  • Calls all listeners registered in the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    Returns void

  • Calls all listeners registered in the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    • args: T[K]

      Data to send in the event.

    Returns void

  • Checks if the emitter has registerd event.

    Parameters

    • event: string

      Name of the event.

    Returns boolean

  • Registers the listener of the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    • listener: ((self: this) => void)

      Listener to execute when the event is called.

        • (self): void
        • Parameters

          • self: this

          Returns void

    Returns this

  • Registers the listener of the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    • listener: ((self: this, args: T[K]) => void)

      Listener to execute when the event is called.

        • (self, args): void
        • Parameters

          • self: this
          • args: T[K]

          Returns void

    Returns this

  • Clears all listeners on the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    Returns void

  • Removes the listener of the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    • listener: ((self: this) => void)
        • (self): void
        • Parameters

          • self: this

          Returns void

    Returns this

  • Removes the listener of the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      Name of the event.

    • listener: ((self: this, args: T[K]) => void)
        • (self, args): void
        • Parameters

          • self: this
          • args: T[K]

          Returns void

    Returns this