/**
 * 事件总线。
 */
import mitt from '../../3rd-libs/mitt';

export default class EventBus {
  constructor(event_name) {
    this.event_name = event_name;

    this.emitter = mitt();
  }

  on(fn) {
    if (typeof fn === 'function') {
      this.emitter.on(this.event_name, (e) => {
        fn(e);
      });
    }
  }

  emit(value) {
    this.emitter.emit(this.event_name, value);
  }

  off() {
    this.emitter.off(this.event_name);
  }
}
