dehub
Version:
Data&Event MessageHub.
103 lines (102 loc) • 3.13 kB
TypeScript
/**
* DEHub 模块
* 这是一个事件中心模块,负责管理组件注册、事件分发和组件间通信
* @module DEHub
*/
import { EmitContext, EventStage, IDEComp, ObjTag, IData, DEEventFunction, ObjectStatus, Tag, ObjWithTag, DERecord } from "./DETypes";
/**
* DEHub配置选项接口
*/
interface DEHubOptions {
/** 应用加载事件延迟时间(ms) */
AppLoadEventDelay: number;
/** 函数执行超时时间(ms) */
FuncExeTimeout: number;
}
/**
* 配置DEHub选项
* @param options - 配置选项
*/
export declare const DEHubConfig: (options: Partial<DEHubOptions>) => void;
/**
* Event Context
* 事件上下文
*/
export declare class EventContext implements EmitContext {
#private;
constructor(emitContext: EmitContext, output: DERecord);
get sender(): ObjWithTag | IData | IDEComp<any>;
get event(): string;
get stage(): EventStage;
get detail(): any;
get status(): ObjectStatus | undefined;
get attribute(): string | undefined;
get property(): string | undefined;
get database(): string | undefined;
/**
* Cancel the event
* 取消事件
*/
get cancel(): boolean;
set cancel(value: boolean);
/**
* Output of the event
* 事件的输出
*/
get output(): DERecord;
/**
* Components of the event
* 事件的组件列表
*/
get components(): Map<string, IDEComp<any>>;
}
/**
* 清除组件会话存储
*/
export declare const clearComponentSession: () => void;
/**
* 根据标签获取组件
* @param tag - 组件标签,可以是Tag对象、ObjTag对象或字符串
* @returns 返回匹配的组件或undefined
*/
export declare const getComponent: (tag: Tag | ObjTag | string) => IDEComp<any> | undefined;
/**
* 注册组件
* @param comp - 要注册的组件
* @returns 返回注册的组件
*/
export declare const regComponent: (comp: IDEComp<any>) => IDEComp<any>;
/**
* 删除组件
* @param comp - 要删除的组件
* @returns Promise<void>
*/
export declare const delComponent: (comp: IDEComp<any>) => Promise<void>;
/**
* 触发事件
* @param context - 事件上下文
* @param proxyTag - 代理标签
* @returns [事件上下文, Promise数组, 事件ID]
*/
export declare const emit: (context: EmitContext, proxyTag?: ObjTag) => [EventContext, Promise<any>[], string];
/**
* 错误处理
* @param sender - 错误发送者
* @param exception - 错误对象
* @returns Promise<[EventContext | null, Promise<any>[]]>
*/
export declare const error: (sender: IDEComp<any> | IData | ObjWithTag, exception: Error | string | unknown) => Promise<(EventContext | Promise<any>[])[] | (never[] | null)[]>;
/**
* 注册事件监听
* @param tagFilter - 标签过滤器
* @param callback - 回调函数
* @param alias - 函数别名
*/
export declare const when: (tagFilter: ObjTag, callback: DEEventFunction, alias?: string) => void;
/**
* 移除事件监听
* @param tagFilter - 标签过滤器
* @param callback - 要移除的回调函数
*/
export declare const stop: (tagFilter: ObjTag, callback: DEEventFunction) => void;
export {};