/** @format */
class PubSub {
    observerBox = [];
    //添加订阅（监听）
    addEventListener(key: string, fn: any) {
        if (!this.observerBox[key]) {
            this.observerBox[key] = [];
        }
        this.observerBox[key].push(fn);
    }
    // 发布（触发）
    trigger(name, ...rest) {
        // Es5
        // let key = arguments[0];
        // let fns = this.observerBox[key];
        let fns = this.observerBox[name];
        if (!fns || fns.length === 0) {
            return;
        }
        for (let i = 0, fn; (fn = fns[i++]); ) {
            fn.apply(this, rest);
        }
    }
}
let pubPush = new PubSub();
export default pubPush;
