import { LMLogger } from './LMLogger';
function x(a, b) { }
const xtype = [1, '2'];
export class LMEmitter extends LMLogger {
    constructor(options) {
        super(options);
        this.destroyed = false;
        this.suspended = false;
        /**
         * For each supported event, we have a Set that holds all the callbacks that should be executed
         * when the event is triggered.
         */
        this.eventSets = {
            gridLayoutChanged: new Set(),
            columnDefsChanged: new Set(),
        };
    }
    on(event, callback) {
        this.eventSets[event].add(callback);
        return () => {
            this.eventSets[event].delete(callback);
        };
    }
    suspend() {
        this.suspended = true;
    }
    resume() {
        this.suspended = false;
    }
    emitSync(event, ...args) {
        if (this.destroyed) {
            return;
        }
        if (this.suspended) {
            return;
        }
        const set = this.eventSets[event];
        set.forEach((callback) => {
            if (this.destroyed) {
                return;
            }
            // @ts-ignore
            callback(...args);
        });
    }
    destroy() {
        if (this.destroyed) {
            return;
        }
        this.destroyed = true;
        Object.values(this.eventSets).forEach((set) => {
            set.clear();
        });
    }
}
