"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const eventemitter3_1 = require("eventemitter3");
const utils_1 = require("./utils");
class EventEmitter extends eventemitter3_1.EventEmitter {
    constructor(conf = {}) {
        const { loadLimit = 1000, eventsSafeInterval = 300 } = conf;
        super();
        this.onAny = (fn) => {
            this.on('any', fn);
        };
        this.offAny = (fn) => {
            this.off('any', fn);
        };
        const overloadHandler = () => {
            console.warn(`There were more than ${loadLimit} events emitted in ${eventsSafeInterval} ms. It might be caused by events' infinite loop`, this.id);
        };
        const dispatch = (0, utils_1.observeOverload)(overloadHandler, {
            limit: loadLimit,
            delay: eventsSafeInterval,
        });
        this.emit = (...args) => {
            super.emit(...args);
            super.emit('any', ...args);
            dispatch();
        };
    }
}
exports.default = EventEmitter;
