Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions library/src/containers/AsyncApi/Standalone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface AsyncAPIState {
class AsyncApiComponent extends Component<AsyncApiProps, AsyncAPIState> {
private readonly registeredPlugins = new Set<string>();
private readonly propsPlugins = new Set<string>();
private readonly eventHandlers = new Map<string, (data: unknown) => void>();

state: AsyncAPIState = {
asyncapi: undefined,
Expand Down Expand Up @@ -125,26 +126,30 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncAPIState> {
);
}

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;

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));
});
}

Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading