Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventEmitter

Hierarchy

  • EventEmitter

Index

Properties

Private _events

_events: Events

addListener

addListener: on = this.on

Alias for emitter.on(name, fn)

removeListener

removeListener: off = this.off

Alias for emitter.off(name, fn)

Accessors

eventNames

  • get eventNames(): string[]
  • Returns an array listing the events for which the emitter has registered listeners

    Returns string[]

Methods

emit

  • emit(name: string, ...args: Arguments): boolean
  • Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each

    Parameters

    • name: string

      name of the event

    • Rest ...args: Arguments

    Returns boolean

    returns true if the event had listeners, false otherwise

listenerCount

  • listenerCount(name: string): number
  • Returns the number of listeners listening to the given event name

    Parameters

    • name: string

      name of the event

    Returns number

    number of listeners listening to the given event name

listeners

  • listeners(name: string): Event[] | []
  • Returns a copy of the array of listeners for the event named eventName

    Parameters

    • name: string

      name of the event

    Returns Event[] | []

off

  • Removes the specified listener from the listener array for the given event name

    Parameters

    • name: string

      name of the event

    • fn: Callback

      callback function

    Returns this

    EventEmitter instance

on

  • Adds the listener function to the end of the listeners array for the given event name

    Parameters

    • name: string

      name of the event

    • fn: Callback

      callback function

    Returns this

    EventEmitter instance

once

  • once(name: string, fn: Callback): this
  • Adds a one-time listener function for the given event name

    Parameters

    • name: string

      name of the event

    • fn: Callback

      callback function

    Returns this

    EventEmitter instance

removeAllListeners

  • removeAllListeners(name?: string): this
  • Removes all listeners, or those of the specified eventName

    It's a bad practice to remove listeners added elsewhere in the code

    Parameters

    • Optional name: string

      name of the event

    Returns this

    EventEmitter instance

Generated using TypeDoc