UNPKG

1.15 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const events_1 = require("events");
4class EventEmitter extends events_1.EventEmitter {
5 on(event, listener) {
6 this.ensureListenerCount(event, (maxListeners) => maxListeners + 1);
7 return super.on(event, listener);
8 }
9 off(event, listener) {
10 return this.removeListener(event, listener);
11 }
12 once(event, listener) {
13 this.ensureListenerCount(event, (maxListeners) => maxListeners + 1);
14 return super.once(event, listener);
15 }
16 addListener(event, listener) {
17 return this.on(event, listener);
18 }
19 removeListener(event, listener) {
20 this.ensureListenerCount(event, (maxListeners) => maxListeners - 1);
21 return super.removeListener(event, listener);
22 }
23 ensureListenerCount(event, count) {
24 const maxListeners = this.getMaxListeners();
25 const listenerCount = this.listenerCount(event);
26 if (listenerCount >= maxListeners) {
27 this.setMaxListeners(count(maxListeners));
28 }
29 }
30}
31exports.EventEmitter = EventEmitter;
32//# sourceMappingURL=emitter.js.map
\No newline at end of file