diff --git a/library/src/containers/AsyncApi/Standalone.tsx b/library/src/containers/AsyncApi/Standalone.tsx index 2beca7519..57d3089af 100644 --- a/library/src/containers/AsyncApi/Standalone.tsx +++ b/library/src/containers/AsyncApi/Standalone.tsx @@ -28,6 +28,7 @@ interface AsyncAPIState { class AsyncApiComponent extends Component { private readonly registeredPlugins = new Set(); private readonly propsPlugins = new Set(); + private readonly eventHandlers = new Map void>(); state: AsyncAPIState = { asyncapi: undefined, @@ -125,11 +126,15 @@ class AsyncApiComponent extends Component { ); } - private handler(eventName: string) { - return (data: unknown) => { - this.props.onPluginEvent!(eventName, data); - }; + private getEventHandler(eventName: string): (data: unknown) => void { + if (!this.eventHandlers.has(eventName)) { + this.eventHandlers.set(eventName, (data: unknown) => { + this.props.onPluginEvent!(eventName, data); + }); + } + return this.eventHandlers.get(eventName)!; } + private setupEventListeners() { const { onPluginEvent } = this.props; const { pm } = this.state; @@ -137,14 +142,14 @@ class AsyncApiComponent extends Component { if (!onPluginEvent) return; PLUGINEVENTS.forEach((event) => { - pm?.on(event, this.handler(event)); + pm?.on(event, this.getEventHandler(event)); }); } private cleanupEventListeners() { const { pm } = this.state; PLUGINEVENTS.forEach((event) => { - pm?.off(event, this.handler(event)); + pm?.off(event, this.getEventHandler(event)); }); } diff --git a/package-lock.json b/package-lock.json index f51a80e93..5db700b4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13775,7 +13775,8 @@ "integrity": "sha512-+xGQY0YyAWCnqy7Cd++hc2JqMYzlm0dG30Jd0beaA64sROr8C4nt8Yc9V5Ro3avlSUDTN0ulqP/VBKi1/lLygw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/gulp-header": { "version": "1.8.12", @@ -19459,6 +19460,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -24260,7 +24262,8 @@ "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/side-channel": { "version": "1.1.0", @@ -28076,7 +28079,7 @@ "@codemirror/lang-yaml": "^6.0.0", "@uiw/codemirror-theme-material": "^4.21.24", "@uiw/react-codemirror": "^4.21.24", - "next": "^16.1.7", + "next": "16.1.7", "react": "^18", "react-dom": "^18", "react-split": "^2.0.14",