Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseEvent<T>

A ts-typed-events event to register callbacks on to be invoked when they are emitted.

Type parameters

  • T = undefined

Hierarchy

Index

Constructors

Properties

Methods

Constructors

Protected constructor

  • Marked as protected to discourage creation outside of createEventEmitter().

    Type parameters

    • T = undefined

    Returns BaseEvent<T>

Properties

Private listeners

listeners: Listener<T>[] = ...

All the current listeners for this event.

Methods

off

  • off(listener: Promise<T> | ((emitted: T) => void)): boolean
  • Removes a callback from this event (regardless of once vs on).

    Returns true if a callback was removed, false otherwise.

    Parameters

    • listener: Promise<T> | ((emitted: T) => void)

      The callback to remove.

    Returns boolean

    True if a callback was removed, false otherwise.

offAll

  • offAll(): number
  • Removes ALL callbacks from this event, regardless of once vs on.

    Returns the number of listeners removed.

    Returns number

    The number of listeners removed.

on

  • on(callback: (data: T) => void): void
  • Attaches a callback to trigger on all emits for this event.

    Parameters

    • callback: (data: T) => void

      The callback to invoke on all emits.

        • (data: T): void
        • Parameters

          • data: T

          Returns void

    Returns void

once

  • once(callback: (emitted: T) => void): void
  • once(): Promise<T>
  • Attaches a callback to trigger on only the first emit for this event. After that event is emitted this callback will automatically be removed.

    Parameters

    • callback: (emitted: T) => void

      The callback to invoke only the next time this event emits, then that callback is removed from this event.

        • (emitted: T): void
        • Parameters

          • emitted: T

          Returns void

    Returns void

  • Attaches a callback to trigger on only the first emit for this event.

    Returns a promise that resolves with the emitted data the next time this event is triggered (only once).

    Returns Promise<T>

    A promise that resolves with the emitted data the next time this event is triggered (only once).

Generated using TypeDoc