Files
SnowLuma/.pnpm-store/v11/files/39/bb29ab5f0255beb41fb1ce2ab5eed2fac3b616430003445358b5dcfb3b2a6c1cbeb35d0fd22515300851611074080c092ed2bfe567b1dc1142236ab7ae2826
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

48 lines
2.3 KiB
Plaintext

/**
* Protocol-independent DOM-style event fan-out.
*
* Owners perform event-specific state updates before calling
* {@link dispatch}. Dispatch then invokes the singular handler followed by a
* snapshot of listeners in insertion order.
*
* @typeParam EventMap - Maps event names to their listener parameter types.
*/
export declare class EventDispatcher<EventMap extends Record<string, unknown>> {
private readonly _eventSlots;
/** Set, replace, or clear the singular handler for an event. */
setHandler<K extends keyof EventMap>(event: K, handler: ((params: EventMap[K]) => void) | undefined): void;
/** Get the singular handler for an event, if one is set. */
getHandler<K extends keyof EventMap>(event: K): ((params: EventMap[K]) => void) | undefined;
/** Add a listener. Listeners run in insertion order after the handler. */
addEventListener<K extends keyof EventMap>(event: K, handler: (params: EventMap[K]) => void): void;
/** Remove the first matching listener, if present. */
removeEventListener<K extends keyof EventMap>(event: K, handler: (params: EventMap[K]) => void): void;
/**
* Dispatch an event to its singular handler and a listener snapshot.
* Listener mutations during dispatch take effect on the next dispatch.
*/
dispatch<K extends keyof EventMap>(event: K, params: EventMap[K]): void;
private _ensureEventSlot;
}
/**
* Tracks which JSON-RPC methods already have a handler registered through the
* owning `App` / `AppBridge`, so a second direct `setRequestHandler` /
* `setNotificationHandler` call for the same method throws instead of
* silently replacing the first handler (the base SDK `Protocol` replaces).
*
* The `on*` setters use {@link replace} for DOM-style replace semantics, and
* `removeRequestHandler` / `removeNotificationHandler` use {@link release}.
*
* @internal
*/
export declare class MethodRegistry {
private readonly _methods;
/** Claim `method`. Throws if a handler is already registered for it. */
claim(method: string, via: string): void;
/** Claim `method` with replace semantics (never throws). */
replace(method: string): void;
/** Release `method` so it can be claimed again. */
release(method: string): void;
has(method: string): boolean;
}