@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
22 lines (21 loc) • 818 B
TypeScript
import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
export interface Listeners {
[name: string]: Set<Listener>;
}
export type Listener<T = any> = (data: T) => void;
type EventName = PluginKey | string;
export type Dispatch<T = any> = (eventName: EventName, data: T) => void;
export declare class EventDispatcher<T = any> {
private listeners;
on(event: string, cb: Listener<T>): void;
has(event: string, cb: Listener<T>): boolean;
off(event: string, cb: Listener<T>): void;
emit(event: string, data: T): void;
destroy(): void;
}
/**
* Creates a dispatch function that can be called inside ProseMirror Plugin
* to notify listeners about that plugin's state change.
*/
export declare function createDispatch<T>(eventDispatcher: EventDispatcher<T>): Dispatch<T>;
export {};