UNPKG

thenavisapp

Version:

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

25 lines (18 loc) 598 B
import type {EventEmitter} from 'node:events'; type Fn = (...args: unknown[]) => void; type Fns = Record<string, Fn>; export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: Readonly<string[]>): () => void { const eventFunctions: Fns = {}; for (const event of events) { const eventFunction = (...args: unknown[]) => { to.emit(event, ...args); }; eventFunctions[event] = eventFunction; from.on(event, eventFunction); } return () => { for (const [event, eventFunction] of Object.entries(eventFunctions)) { from.off(event, eventFunction); } }; }