Skip to content

Commit 52b1c55

Browse files
committed
fix: remove double event context
1 parent d34b1fa commit 52b1c55

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed
Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import EventEmitter from 'node:events';
22
import type { CommandKit } from '../CommandKit';
33
import type { AsyncFunction, GenericFunction } from '../context/async-context';
4-
import { runInEventWorkerContext } from '../app/events/EventWorkerContext';
54

65
export type ListenerFunction = GenericFunction | AsyncFunction;
76

@@ -21,24 +20,15 @@ export class CommandKitEventsChannel {
2120
}
2221

2322
public on(namespace: string, event: string, listener: ListenerFunction) {
24-
this.emitter.on(
25-
`${namespace}:${event}`,
26-
this.prepareListener(namespace, event, listener),
27-
);
23+
this.emitter.on(`${namespace}:${event}`, listener);
2824
}
2925

3026
public off(namespace: string, event: string, listener: ListenerFunction) {
31-
this.emitter.off(
32-
`${namespace}:${event}`,
33-
this.prepareListener(namespace, event, listener),
34-
);
27+
this.emitter.off(`${namespace}:${event}`, listener);
3528
}
3629

3730
public once(namespace: string, event: string, listener: ListenerFunction) {
38-
this.emitter.once(
39-
`${namespace}:${event}`,
40-
this.prepareListener(namespace, event, listener),
41-
);
31+
this.emitter.once(`${namespace}:${event}`, listener);
4232
}
4333

4434
public emit(namespace: string, event: string, ...args: any[]) {
@@ -54,28 +44,4 @@ export class CommandKitEventsChannel {
5444
this.emitter.removeAllListeners(namespace);
5545
}
5646
}
57-
58-
private prepareListener<L extends ListenerFunction>(
59-
namespace: string,
60-
event: string,
61-
listener: L,
62-
): L {
63-
return ((...args) => {
64-
return runInEventWorkerContext(
65-
{
66-
arguments: args,
67-
commandkit: this.commandkit,
68-
data: {
69-
event,
70-
namespace,
71-
listeners: [],
72-
path: `virtual:${namespace}/${event}`,
73-
},
74-
event,
75-
namespace,
76-
},
77-
() => listener(...args),
78-
);
79-
}) as L;
80-
}
8147
}

0 commit comments

Comments
 (0)