Merge pull request #7391 from hsm-lv/fix-event

fix:当按钮本身事件触发后,无法触发按钮的广播事件 Close #7358
This commit is contained in:
hsm-lv 2023-07-06 17:16:43 +08:00 committed by GitHub
commit cb06cb170d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,10 +128,13 @@ export const bindEvent = (renderer: any) => {
});
}
}
return () => {
return (eventName?: string) => {
// eventName用来避免过滤广播事件
rendererEventListeners = rendererEventListeners.filter(
(item: RendererEventListener) => item.renderer !== renderer
(item: RendererEventListener) =>
item.renderer !== renderer && eventName !== undefined
? item.type !== eventName
: true
);
};
}
@ -147,7 +150,7 @@ export async function dispatchEvent(
data: any,
broadcast?: RendererEvent<any>
): Promise<RendererEvent<any> | void> {
let unbindEvent: (() => void) | null | undefined = null;
let unbindEvent: ((eventName?: string) => void) | null | undefined = null;
const eventName = typeof e === 'string' ? e : e.type;
renderer?.props?.env?.beforeDispatchEvent?.(
@ -183,6 +186,7 @@ export async function dispatchEvent(
data,
scoped
});
// 过滤&排序
const listeners = rendererEventListeners
.filter(
@ -198,7 +202,7 @@ export async function dispatchEvent(
const checkExecuted = () => {
executedCount++;
if (executedCount === listeners.length) {
unbindEvent?.();
unbindEvent?.(eventName);
}
};
for (let listener of listeners) {