"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class CommandCommand {
    constructor(parser) {
        this.listeners = {};
        this.parser = parser;
    }
    triggerCommand(command, params) {
        const listeners = this.listeners[command];
        for (var i = 0; i < listeners.length; i++) {
            listeners[i](params);
        }
    }
    registerCommand(command, callback, isOnly = false) {
        if (isOnly) {
            this.listeners[command] = [callback];
        }
        else {
            if (!this.listeners[command]) {
                this.listeners[command] = [];
            }
            if (!this.listeners[command].find(item => {
                return item === callback;
            })) {
                this.listeners[command].push(callback);
            }
        }
    }
    removeCommand(command, callback, isOnly = false) {
        if (typeof callback === 'boolean') {
            isOnly = true;
        }
        if (isOnly) {
            this.listeners[command] = [];
        }
        else {
            if (!this.listeners[command]) {
                this.listeners[command] = [];
            }
            this.listeners[command] = this.listeners[command].filter(callbackItem => {
                return callbackItem != callback;
            });
        }
    }
}
exports.default = CommandCommand;
//# sourceMappingURL=CommonCommand.js.map