(from: EventEmitter, to: EventEmitter, events: readonly string[])
| 1 | import type {EventEmitter} from 'node:events'; |
| 2 | |
| 3 | export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: readonly string[]): () => void { |
| 4 | const eventFunctions = new Map<string, (...arguments_: unknown[]) => void>(); |
| 5 | |
| 6 | for (const event of events) { |
| 7 | const eventFunction = (...arguments_: unknown[]) => { |
| 8 | to.emit(event, ...arguments_); |
| 9 | }; |
| 10 | |
| 11 | eventFunctions.set(event, eventFunction); |
| 12 | from.on(event, eventFunction); |
| 13 | } |
| 14 | |
| 15 | return () => { |
| 16 | for (const [event, eventFunction] of eventFunctions) { |
| 17 | from.off(event, eventFunction); |
| 18 | } |
| 19 | }; |
| 20 | } |
no test coverage detected
searching dependent graphs…