const state = {
  logs: [],
  axiosCancelArr:[],
}

const mutations = {
  ADD_ERROR_LOG: (state, log) => {
    state.logs.push(log)
  },
  CLEAR_ERROR_LOG: (state) => {
    state.logs.splice(0)
  },
  PUSH_CANCEL:(state,cancel)=>{
    state.axiosCancelArr.push(cancel.cancelToken);
  },
  CLEAR_CANCEL:(state)=>{
    state.axiosCancelArr.forEach(e=>{
      e && e()
    });
    state.axiosCancelArr = [];
  }
}

const actions = {
  addErrorLog({ commit }, log) {
    commit('ADD_ERROR_LOG', log)
  },
  clearErrorLog({ commit }) {
    commit('CLEAR_ERROR_LOG')
  },
  pushCancel({commit},cancel){
    commit('PUSH_CANCEL',cancel)
  },
  clearCancel({commit}){
    commit('CLEAR_CANCEL');
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
