import { ActionTree , GetterTree , Module , MutationTree } from 'vuex' ; import { IRootState } from '../store' ; import { Battle , BattleService } from '.' ; const namespaced = true ; export { Battle } ; export interface IBattleState { battles ? : Battle [ ] ; error : boolean ; } ; const state = { battles : [ ] , error : false } ; const actions = { async clearCache ( { commit } ) { try { await BattleService . clearCache ( ) ; commit ( 'battlesCleared' ) ; } catch ( error ) { commit ( 'battleError' ) ; throw error ; } } , async fetchBattles ( { commit } ) { try { const battles = await BattleService . getBattles ( ) ; commit ( 'battlesLoaded' , battles ) ; } catch ( error ) { commit ( 'battleError' ) ; throw error ; } } , } ; const getters = { } ; const mutations = { battlesCleared ( state ) { state . error = false ; state . battles = [ ] ; } , battlesLoaded ( state , battles ) { state . error = false ; state . battles = battles ; } , battleError ( state ) { state . error = true ; state . battles = [ ] ; } } ; export const battleStore = { namespaced , state , getters , actions , mutations , } ;