1
This commit is contained in:
@ -73,7 +73,18 @@ export const once = (eventName: string, callback: (...args: unknown[]) => void,
|
||||
};
|
||||
|
||||
export const emit = (eventName: string, ...args: unknown[]): Emitter => {
|
||||
return eventBus.emit(eventName, ...args);
|
||||
// 触发内部事件总线
|
||||
const result = eventBus.emit(eventName, ...args);
|
||||
|
||||
// 同时触发 window 自定义事件,方便外部监听
|
||||
if (typeof window !== 'undefined') {
|
||||
const customEvent = new CustomEvent(eventName, {
|
||||
detail: args[0] // 传递第一个参数作为 detail
|
||||
});
|
||||
window.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const removeAllListeners = (eventName?: string): Emitter => {
|
||||
|
||||
Reference in New Issue
Block a user