mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-25 23:25:02 +00:00
## Summary - Removes all `any` types from the load3d module - Uses generics for EventCallback to provide type-safe event handling - Types node parameters with LGraphNode - Types onExecuted callback with NodeExecutionOutput - Types Camera Config property casts with CameraConfig interface ## Changes - `interfaces.ts`: EventCallback<T> generic, EventManagerInterface generic methods - `EventManager.ts`: Generic emitEvent/addEventListener/removeEventListener - `AnimationManager.ts`: setupModelAnimations originalModel typed as GLTF union - `Load3d.ts`: Event listener methods use EventCallback<T> - `load3d.ts`: Node params typed as LGraphNode, onExecuted uses NodeExecutionOutput, CameraConfig casts ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes - [x] `pnpm test:unit` passes ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8064-Road-to-No-Explicit-Any-Part-5-load3d-Module-2e96d73d365081efbc01f2d8a4f3c11f) by [Unito](https://www.unito.io)
27 lines
786 B
TypeScript
27 lines
786 B
TypeScript
import { type EventCallback, type EventManagerInterface } from './interfaces'
|
|
|
|
export class EventManager implements EventManagerInterface {
|
|
private listeners: Record<string, EventCallback[]> = {}
|
|
|
|
addEventListener<T>(event: string, callback: EventCallback<T>): void {
|
|
if (!this.listeners[event]) {
|
|
this.listeners[event] = []
|
|
}
|
|
this.listeners[event].push(callback as EventCallback)
|
|
}
|
|
|
|
removeEventListener<T>(event: string, callback: EventCallback<T>): void {
|
|
if (this.listeners[event]) {
|
|
this.listeners[event] = this.listeners[event].filter(
|
|
(cb) => cb !== callback
|
|
)
|
|
}
|
|
}
|
|
|
|
emitEvent<T>(event: string, data: T): void {
|
|
if (this.listeners[event]) {
|
|
this.listeners[event].forEach((callback) => callback(data))
|
|
}
|
|
}
|
|
}
|