Skip to main content
Module

x/evtemitter/mod.ts>EventEmitter

Eventemitter for deno.
Go to Latest
class EventEmitter
extends EventTarget
import { EventEmitter } from "https://deno.land/x/evtemitter@2.0.0/mod.ts";

Properties

protected
__listeners__: Map<keyof T, Set<CustomEventCallbackOn>>
dispatch

Alias for emit

listeners
publish

same as emit. Used for pub / sub conventions

Methods

protected
getOrCreateListeners<K extends keyof T & string>(type: K): Set<CustomEventCallbackOn>
emit<K extends keyof T & string>(type: K, ...detail: T[K]): this

Emit an event with given detail Calls all listeners that listen to the emitted event

getListeners<K extends keyof T & string>(type: K): Set<CustomEventCallbackOn>

Get all EventListeners for a specific Event

getListeners(): Map<string, Set<CustomEventCallbackOn>>

Get all EventListeners

off<K extends keyof T & string>(): this

remove all EventListeners

off<K extends keyof T & string>(type: K): this

remove all EventListeners for a specific event

off<K extends keyof T & string>(types: K[]): this

remove all EventListeners for multiple specific events

off<K extends keyof T & string>(type: K, callback: CustomEventCallbackOn<T[K]>): this

remove a specific EventListener for a specific event

off<K extends keyof T & string>(types: K[], callback: CustomEventCallbackOn<T[K]>): this

remove a specific EventListener for multiple specific events

on<K extends keyof T & string>(type: K, callback: CustomEventCallbackOn<T[K]>): this

add a callback to an event

on<K extends keyof T & string>(types: K[], callback: CustomEventCallbackOn<T[K]>): this

add a callback to multiple events

once<K extends keyof T & string>(type: K, callback: CustomEventCallbackOn<T[K]>): this

add a callback to an event only once. After that, the listener is removed.

once<K extends keyof T & string>(types: K[], callback: CustomEventCallbackOn<T[K]>): this

add a callback to multiple events only once. After that, the listener is removed.

pull<K extends keyof T & string>(type: K): Promise<T[K]>

wait for an event to be dispatched

pull<K extends keyof T & string>(type: K, timeout: number): Promise<T[K]>

wait for an event to be dispatched and reject after a specific amount of milliseconds

subscribe<K extends keyof T & string>(type: K, callback: CustomEventCallbackOn<T[K]>): Fn<never, void>

Subscribe method. Returns a cleanup function to remove the added EventListener

Static Methods

createEvent<Type extends string, Detail>(
type: Type,
detail?: Detail,
init?: Omit<CustomEventInit, "detail">,
): TypedCustomEvent<Type, Detail>