Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Emitter

A simple event emitter interface for sending arbitrary events to any number of listeners.

import { Emitter } from 'goodish'
const bus = new Emitter()
bus.on('hello', (msg: string) => {
  console.log('hello', msg)
})
bus.emit('hello', 'world')
// # 'hello world' logged in console
export
class

Emitter

Hierarchy

  • Emitter

Index

Properties

Private eventCallbacks

eventCallbacks: object

Type declaration

Methods

dispatch

  • dispatch(eventName: string, ...args: any[]): void
  • Dispatch an event with eventName using the 'call' method

    Parameters

    • eventName: string
    • Rest ...args: any[]

    Returns void

dispatchApply

  • dispatchApply(eventName: string, args?: any[]): void
  • Dispatch an event with eventName using the 'apply' method

    Parameters

    • eventName: string
    • Default value args: any[] = []

    Returns void

emit

  • emit(eventName: string, ...args: any[]): void
  • Alias for the dispatch method

    Parameters

    • eventName: string
    • Rest ...args: any[]

    Returns void

hasListeners

  • hasListeners(): boolean
  • Getter to check if any listeners are present on this emitter

    Returns boolean

off

  • off(eventName: string): void
  • off(eventName: string, callback: Function): void
  • off(eventName: string, callback: Function, force: boolean): void
  • Remove an event callback by reference

    Parameters

    • eventName: string

    Returns void

  • Parameters

    • eventName: string
    • callback: Function

    Returns void

  • Parameters

    • eventName: string
    • callback: Function
    • force: boolean

    Returns void

on

  • on(eventName: string, callback: Function, context?: object): void
  • Add an event callback with optional context

    Parameters

    • eventName: string
    • callback: Function
    • Optional context: object

    Returns void

register

  • register(eventName: string): void
  • Register an event type by name. This method is called when the 'on' method is called if an event of that type has not been registered yet.

    Parameters

    • eventName: string

    Returns void

removeListeners

  • removeListeners(): void
  • Remove all listeners from this instance

    Returns void

Generated using TypeDoc