Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventEmitter

Simple event emitter class.

Supports "omni-listeners" through its omniEvent static property. An omni-listener is added/removed as any other listener but it will be triggered with ANY event rather than with a specific one.

Events can be strings or symbols. Internally, uses Map and Set instances to deal with events and listeners so in theory anything that can be used as a Map key can be used as an event, only strings and symbols are guaranteed to work however.

Hierarchy

  • EventEmitter<EventEmitterMixin, this> & EventEmitterMixin<this>
    • EventEmitter

Index

Properties

Accessors

Methods

Properties

Private listeners

listeners: Map<string | symbol, Set<EventCallback>> = new Map()

Map of registered event listeners with this instance.

Accessors

Static omniEvent

  • get omniEvent(): symbol

Methods

emit

  • emit(type: string | symbol, ...args: any[]): void
  • Emit an event to all event listeners register for that specific event and omni-listeners (listeners registered wising * as the event type).

    Parameters

    • type: string | symbol

      The event to emit, cannot be *

    • Rest ...args: any[]

      Parameters to pass to the callback functions registered for this event

    Returns void

off

on

  • Register an event listener callback for the specified event.

    NOTE: Pass * as the event type to listen to all event emitted by this instance.

    Parameters

    • type: string | symbol

      The event to listen for

    • callback: EventCallback

      Called when the event is emitted by this instance

    Returns void

Static mixin

  • Mixin method that holds the EventEmitter implementation, this function is exposed through EventEmitter.mixin.

    Type parameters

    • T

    Parameters

    • Parent: T

      The parent class into which the EventEmitter implementation will be mixed in.

    Returns EventEmitter & T

Generated using TypeDoc