Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Event<T>

A specialized Event that holds a reference to its own emit function. This allows any code with access to the Event to also trigger emits.

Type parameters

  • T = undefined

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Event<T>(): Event<T>

Properties

emit

emit: Emitter<T, Event<T>> = ...

Emits a value to all the listeners, triggering their callbacks. Returns true if the event had listeners emitted to, false otherwise. Because this exists on the event, any code with access to this event can trigger the callback for all listeners.

param

If the Event has a type, this is the data of that type to emit to all listeners. If no type (undefined) this argument should be omitted.

returns

True if the event had listeners emitted to, false otherwise.

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