Skip to content

AsyncEventSource<EventMap>

Async event emitter implementation.

Import:

import type { AsyncEventSource } from 'obsidian-dev-utils/async-events';

Example:

// Untyped (default) — any event name, any args:
const events = new AsyncEvents();
events.on('my-event', (arg1: string) => { ... });
// Typed — only declared events with correct args:
interface MyEventMap {
save: [data: string];
load: [id: number, force: boolean];
}
const events = new AsyncEvents<MyEventMap>();
events.on('save', (data) => { ... }); // data: string — autocomplete on event name
events.on('load', (id, force) => { ... }); // id: number, force: boolean

Signature:

export interface AsyncEventSource<EventMap extends EventMapConstraint<EventMap> = EventMapBase> extends GenericAsyncEventSource

Extends: GenericAsyncEventSource

Properties

PropertyTypeDescription
[ASYNC_EVENT_MAP]?EventMapPhantom marker that makes EventMap inferable from an AsyncEventSource (e.g. via Source extends AsyncEventSource<infer EventMap>). Never present at runtime.

Methods

MethodReturnsDescription
off(name, callback)voidRemove an event listener.
offref(eventRef)voidRemove an event listener by reference.
(Inherited from GenericAsyncEventSource)
on(name, callback, thisArg?)AsyncEventRefAdd an event listener.
once(name, callback, thisArg?)AsyncEventRefAdd an event listener that will be triggered only once.

Links to this page: