|
1 | | -import events from "node:events"; |
| 1 | +import EventEmitter from "node:events"; |
2 | 2 |
|
3 | 3 | const newImpl = function () { |
4 | | - return new events.EventEmitter(); |
| 4 | + return new EventEmitter(); |
5 | 5 | } |
6 | 6 | export { newImpl as new }; |
7 | 7 |
|
8 | | -export function listenersLengthImpl(emitter, event) { |
9 | | - return emitter.listeners(event).length; |
10 | | -} |
11 | | - |
12 | | -export function setMaxListenersImpl(emitter, max) { |
13 | | - emitter.setMaxListeners(max); |
14 | | -} |
15 | | - |
16 | | -export function onImpl(emitter, eventName, cb) { |
17 | | - emitter.on(eventName, cb); |
18 | | - return cb; |
19 | | -} |
| 8 | +// addEventListener - not implemented; alias to `on` |
| 9 | +export const unsafeEmitFn = (emitter) => emitter.emit.bind(emitter); |
| 10 | +export const eventNamesImpl = (emitter) => emitter.eventNames(); |
| 11 | +export const symbolOrStr = (left, right, sym) => typeof sym == "symbol" ? left(sym) : right(sym); |
| 12 | +export const getMaxListenersImpl = (emitter) => emitter.getMaxListeners(); |
| 13 | +export const listenerCountImpl = (emitter, eventName) => emitter.listenerCount(eventName); |
| 14 | +// listeners - not implemented; returned functions cannot be used in type-safe way. |
| 15 | +export const unsafeOff = (emitter, eventName, cb) => emitter.off(eventName, cb); |
| 16 | +export const unsafeOn = (emitter, eventName, cb) => emitter.on(eventName, cb); |
| 17 | +export const unsafeOnce = (emitter, eventName, cb) => emitter.once(eventName, cb); |
| 18 | +export const unsafePrependListener = (emitter, eventName, cb) => emitter.prependListener(eventName, cb); |
| 19 | +export const unsafePrependOnceListener = (emitter, eventName, cb) => emitter.prependOnceListener(eventName, cb); |
| 20 | +// removeAllListeners - not implemented; bad practice |
| 21 | +// removeEventListener - not implemented; alias to `off` |
| 22 | +export const setMaxListenersImpl = (emitter, max) => emitter.setMaxListeners(max); |
| 23 | +// rawListeners - not implemented; returned functions cannot be used in type-safe way. |
20 | 24 |
|
21 | | -export function offImpl(emitter, eventName, cb) { |
22 | | - emitter.off(eventName, cb); |
23 | | -} |
24 | | - |
25 | | -export function onceEventListener(emitter, eventName, cb) { |
26 | | - emitter.once(eventName, cb); |
27 | | -} |
28 | | - |
29 | | -export function emitImpl(emitter, eventName) { |
30 | | - return function (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
31 | | - emitter.emit(eventName, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) |
32 | | - }; |
33 | | -} |
34 | | -const undefined_ = undefined |
35 | | -export { undefined_ as undefined } |
0 commit comments