Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AmittEmitter<Keys, Events>

package

@jwn-js/amitt

description

async events bus

Type parameters

  • Keys: EventType = any

  • Events: Map<Keys, Set<any>> = Map<Keys, Set<any>>

Hierarchy

  • AmittEmitter

Index

Constructors

Methods

Constructors

  • new AmittEmitter<Keys, Events>(): AmittEmitter<Keys, Events>
  • Type parameters

    • Keys: EventType = any

    • Events: Map<Keys, Set<any>, Events> = Map<Keys, Set<any>>

    Returns AmittEmitter<Keys, Events>

Methods

  • emit<U, V>(type: Keys, ...args: U): V
  • Invoke all handlers for given type

    Type parameters

    • U: any[] = []

    • V: any[] = any[]

    Parameters

    • type: Keys

      event type

    • Rest ...args: U

      event argiments

    Returns V

    array of responses handlers, it can be Promise

  • off<U>(type: Keys, handler: U): boolean
  • Remove an event handler for given type

    Type parameters

    • U = any

    Parameters

    • type: Keys

      event type

    • handler: U

      handler

    Returns boolean

    • is handler has been removed
  • on<U, V>(type: Keys, handler: (...args: [...U[], { once: boolean; type: Keys }]) => V | Promise<V>): boolean
  • Register an event handler for given type

    Type parameters

    • U: any[] = []

    • V = any

    Parameters

    • type: Keys

      type of event

    • handler: (...args: [...U[], { once: boolean; type: Keys }]) => V | Promise<V>

      fantion handler

        • (...args: [...U[], { once: boolean; type: Keys }]): V | Promise<V>
        • Parameters

          • Rest ...args: [...U[], { once: boolean; type: Keys }]

          Returns V | Promise<V>

    Returns boolean

    if handler has been adding

  • once<U, V>(type: Keys, handler: (...args: [...U[], { once: boolean; type: Keys }]) => V | Promise<V>): boolean
  • Set event that invoke only one time

    Type parameters

    • U: any[] = []

    • V = any

    Parameters

    • type: Keys
    • handler: (...args: [...U[], { once: boolean; type: Keys }]) => V | Promise<V>
        • (...args: [...U[], { once: boolean; type: Keys }]): V | Promise<V>
        • Parameters

          • Rest ...args: [...U[], { once: boolean; type: Keys }]

          Returns V | Promise<V>

    Returns boolean

    is handler added

Generated using TypeDoc