"use strict";
cc._RF.push(module, '1be932YNPdN868qHa6IUyoA', 'EventMgr');
// OP13/script/EventMgr.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EventMgr = /** @class */ (function () {
    function EventMgr() {
        // 所有事件的监听器
        this.es = {};
    }
    EventMgr.prototype.on = function (eventName, cb, target) {
        if (!this.es[eventName]) {
            this.es[eventName] = [];
        }
        this.es[eventName].push({
            cb: cb,
            once: false,
            target: target,
        });
    };
    EventMgr.prototype.once = function (eventName, cb, target) {
        if (!this.es[eventName]) {
            this.es[eventName] = [];
        }
        this.es[eventName].push({
            cb: cb,
            once: true,
            target: target,
        });
    };
    EventMgr.prototype.emit = function (eventName, params) {
        var listeners = this.es[eventName] || [];
        var l = listeners.length;
        for (var i = 0; i < l; i++) {
            var _a = listeners[i], cb = _a.cb, once = _a.once, target = _a.target;
            var args = [eventName, params];
            cb.apply(target, args);
            if (once) {
                listeners.splice(i, 1);
                i--;
                l--;
            }
        }
    };
    EventMgr.prototype.off = function (eventName, cb, target) {
        // clean all
        if (eventName === undefined) {
            this.es = {};
        }
        else {
            if (cb === undefined) {
                // clean the eventName's listeners
                delete this.es[eventName];
            }
            else if (cb === null) {
                if (!target) {
                    return;
                }
                var listeners = this.es[eventName] || [];
                // clean the event and listener
                var l = listeners.length;
                for (var i = 0; i < l; i++) {
                    if (listeners[i].target === target) {
                        listeners.splice(i, 1);
                        i--;
                        l--;
                    }
                }
            }
            else {
                var listeners = this.es[eventName] || [];
                // clean the event and listener
                var l = listeners.length;
                for (var i = 0; i < l; i++) {
                    if (listeners[i].cb === cb && listeners[i].target === target) {
                        listeners.splice(i, 1);
                        i--;
                        l--;
                    }
                }
            }
        }
    };
    return EventMgr;
}());
exports.default = new EventMgr();

cc._RF.pop();