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 nameevents.on('load', (id, force) => { ... }); // id: number, force: booleanSignature:
export interface AsyncEventSource<EventMap extends EventMapConstraint<EventMap> = EventMapBase> extends GenericAsyncEventSourceExtends: GenericAsyncEventSource
Properties
| Property | Type | Description |
|---|---|---|
| [ASYNC_EVENT_MAP]? | EventMap | Phantom marker that makes EventMap inferable from an AsyncEventSource (e.g. via Source extends AsyncEventSource<infer EventMap>). Never present at runtime. |
Methods
| Method | Returns | Description |
|---|---|---|
| off(name, callback) | void | Remove an event listener. |
| offref(eventRef) | void | Remove an event listener by reference. (Inherited from GenericAsyncEventSource) |
| on(name, callback, thisArg?) | AsyncEventRef | Add an event listener. |
| once(name, callback, thisArg?) | AsyncEventRef | Add an event listener that will be triggered only once. |
Links to this page: