
import error from '../../../common/error';
import topicListener from '../common/topicListener';
import prepareHUYA from '../common/prepareHUYA';
import TOPICS from '../const/topic';

const { LIFE_LOAD } = TOPICS;
/**
 * 加载成功触发
 * @param {*} data 
 */
const onLoad = data => {
  prepareHUYA()
    .then(() => {
      topicListener.emit(LIFE_LOAD, data);
    })
    .catch(err => error.emit(err));
};

/**
 * 生命周期
 */
export default {
  init() {
    if (document.readyState === 'complete') {
      return onLoad({});
    }
    window.addEventListener('load', () => onLoad({}));
  }
}
