/** * @file * * Mock of Obsidian's `Events`, the named-event emitter many Obsidian classes extend. */ import type { EventRef as EventRefOriginal, Events as EventsOriginal } from 'obsidian'; import type { EventsEntry } from '../internal/types.mjs'; /** * Mock of Obsidian's `Events`, a working in-memory event emitter. * * Handlers are kept per event name and run synchronously, in registration order, by {@link Events.trigger}. */ export declare class Events { /** * The registered handlers, keyed by event name, in registration order. Obsidian keeps them under this name too. */ _: Record; /** * Creates an emitter with no handlers. */ constructor(); /** * Mock-only factory: creates an emitter, spyable via `vi.spyOn(Events, 'create__')`. * * @returns The new emitter. */ static create__(): Events; /** * Mock-only: views a value typed as Obsidian's `Events` as this mock. * * @param value - The value typed as the original `Events`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: EventsOriginal): Events; /** * Mock-only: views this mock as Obsidian's `Events` type. * * @returns The same object, typed as the original `Events`. */ asOriginalType__(): EventsOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(Events.prototype, 'constructor__')`. */ constructor__(): void; /** * Removes every registration of a handler for an event. As in Obsidian, the event's entry list is dropped once it * is empty. * * @param name - The event name. * @param callback - The handler to remove, compared by identity. */ off(name: string, callback: (...data: unknown[]) => unknown): void; /** * Removes the one registration an event ref was returned for, compared by identity, so other registrations of the * same handler stay. * * @param ref - The ref returned by {@link Events.on}; a ref without a name is ignored. */ offref(ref: EventRefOriginal): void; /** * Registers a handler for an event. * * @param name - The event name. * @param callback - The handler, called with the arguments passed to {@link Events.trigger}. * @param context - The `this` the handler is called with. * @returns The stored registration itself, as in Obsidian: a ref carrying the emitter, name, handler and context, * for {@link Events.offref} or `Component.registerEvent`. */ on(name: string, callback: (...data: unknown[]) => unknown, context?: unknown): EventRefOriginal; /** * Calls every handler registered for an event, in registration order, through {@link Events.tryTrigger}. As in * Obsidian, it iterates a copy of the list, so handlers added or removed while it runs do not change this pass. * * @param name - The event name. * @param data - The arguments passed to each handler. */ trigger(name: string, ...data: unknown[]): void; /** * Calls the handler of a single event ref with its registered context as `this`. As in Obsidian, an error the * handler throws does not propagate: it is rethrown from a `setTimeout(0)`, so the remaining handlers still run * and the error surfaces as an uncaught exception. * * @param $event - The ref returned by {@link Events.on}. * @param $arguments - The arguments passed to the handler. */ tryTrigger($event: EventRefOriginal, $arguments: unknown[]): void; private setEntries; }