Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventEmitter<EventType>

A class used to receive and emit events.

Type parameters

  • EventType: string

Hierarchy

Index

Constructors

constructor

Properties

events

events: {}

Type declaration

Methods

addListener

  • addListener(event: EventType, listener: Listener): this
  • Adds the listener function to the end of the list of listeners for the specified event. No checks are made to see if listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added, and called, multiple times.

    Parameters

    • event: EventType

      The name of the event.

    • listener: Listener

      The callback function.

    Returns this

emit

  • emit(event: EventType, ...args: any[]): boolean
  • Emits the event to all of its registered listeners.

    Parameters

    • event: EventType

      The event to be emitted to its listeners.

    • Rest ...args: any[]

      The arguments to be passed along with the event.

    Returns boolean

    false if there were no listeners for the emitted event.

off

  • off(event: EventType, listener: Listener): this

on

  • on(event: EventType, listener: Listener): this

removeAllListeners

  • removeAllListeners(event: EventType): this
  • Removes all previously registered listeners for the specified event.

    Parameters

    • event: EventType

      The name of the event.

    Returns this

removeListener

  • removeListener(event: EventType, listener: Listener): this
  • Removes the most recently added instance of listener from the list of listeners for the specified event.

    Once an event has been emitted, all listeners attached to it at the time of emitting will be called in order. This implies that any removeListener or removeAllListeners calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events will behave as expected.

    Parameters

    • event: EventType

      The name of the event.

    • listener: Listener

      The callback function to be removed.

    Returns this