import messager from './messager';
import EventManager from '../../../manager/eventManager';

/**
 * 统一管理Topic的监听事件，messager.on 只监听一次，
 * 1. tp 事件分类，可用于按分类注销事件
 * 2. 事件传输流: messager => topicListene
 */
class TopicListener {
    constructor() {
        this._eventer = new EventManager();
        messager.on(data => {
            const { topic, message } = data;
            this._eventer.emit(topic, message || {});
        });
    }

    on(topic, cb, tp) {
        this._eventer.on(topic, cb, tp);
    }

    off(topic, cb, tp) {
        this._eventer.off(topic, cb, tp);
    }
}

export default new TopicListener();
