mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-26 09:44:06 +00:00
feat: allow custom event names in ComfyApi.addEventListener (#9140)
## Summary - Add string fallback overloads to `addEventListener` and `removeEventListener` on `ComfyApi` - Extensions can now listen for custom event names without TypeScript rejecting unknown event names - Known events still get full type safety via the generic overload; unknown strings fall through to `CustomEvent` ## Related Issue - Fixes #2088 ## QA - Verify existing typed event listeners (e.g. `api.addEventListener('status', ...)`) still infer correct types - Verify custom event names (e.g. `api.addEventListener('my-custom-event', ...)`) compile without errors ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9140-feat-allow-custom-event-names-in-ComfyApi-addEventListener-3116d73d36508128aad3fab98c34fac3) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
1f0ca18737
commit
aab09b5f99
@@ -475,6 +475,23 @@ export class ComfyApi extends EventTarget {
|
||||
super.removeEventListener(type, callback as EventListener, options)
|
||||
}
|
||||
|
||||
addCustomEventListener(
|
||||
type: string,
|
||||
callback: ((event: CustomEvent<unknown>) => void) | null,
|
||||
options?: AddEventListenerOptions | boolean
|
||||
) {
|
||||
super.addEventListener(type, callback as EventListener, options)
|
||||
this._registered.add(type)
|
||||
}
|
||||
|
||||
removeCustomEventListener(
|
||||
type: string,
|
||||
callback: ((event: CustomEvent<unknown>) => void) | null,
|
||||
options?: EventListenerOptions | boolean
|
||||
) {
|
||||
super.removeEventListener(type, callback as EventListener, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a custom event.
|
||||
* Provides type safety for the contravariance issue with EventTarget (last checked TS 5.6).
|
||||
|
||||
Reference in New Issue
Block a user