UNPKG

@enonic-types/lib-event

Version:

Type definitions for lib-event.

82 lines (81 loc) 2.12 kB
declare global { interface XpLibraries { '/lib/xp/event': typeof import('./event'); } } export interface ListenerParams<EventData extends object> { /** * Event type pattern */ type: string; /** * Callback event listener */ callback: (event: EnonicEvent<EventData>) => void; /** * Local events only (default to false) */ localOnly?: boolean; } export interface SendParams<EventData extends object> { /** * Event type */ type: string; /** * `true` if it should be distributed in cluster */ distributed?: boolean; /** * Additional data for event. */ data?: EventData; } export interface EnonicEvent<EventData extends object = EnonicEventData> { type: string; timestamp: number; localOrigin: boolean; distributed: boolean; data: EventData; } export interface EnonicEventData { nodes: EnonicEventDataNode[]; state?: string; } export interface EnonicEventDataNode { id: string; path: string; branch: string; repo: string; newPath?: string; } /** * Event functions. * * @example * var eventLib = require('/lib/xp/event'); * * @module event */ /** * This function adds a event listener. * * @example-ref examples/event/listener.js * * @param {object} params Listener parameters. * @param {string} params.type Event type pattern. * @param {function} params.callback Callback event listener. * @param {boolean} params.localOnly Local events only (default to false). */ export declare function listener<EventData extends object = EnonicEventData>(params: ListenerParams<EventData>): void; /** * This function sends a custom event. All custom events are prefixed 'custom.'. * * @example-ref examples/event/send.js * * @param {object} event Event to send. * @param {string} event.type Event type. * @param {boolean} event.distributed True if it should be distributed in cluster. * @param {object} event.data Additional data for event. */ export declare function send<EventData extends object = object>(event: SendParams<EventData>): void;