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