import { ActionTree , GetterTree , Module , MutationTree } from 'vuex' ; import { TankService } from './tankService' ; import { IRootState } from '../store' ; import { Tank } from './types' ; const namespaced = true ; export { Tank } ; export interface ITankState { tanks ? : Tank [ ] ; error : boolean ; } ; const state = { tanks : [ ] , error : false } ; const actions = { async clearCache ( { commit } ) { try { await TankService . clearCache ( ) ; commit ( 'tanksCleared' ) ; } catch ( error ) { commit ( 'tankError' ) ; throw error ; } } , async fetchTanks ( { commit } ) { try { const tanks = await TankService . getTanks ( ) ; commit ( 'tanksLoaded' , tanks ) ; } catch ( error ) { commit ( 'tankError' ) ; throw error ; } } , } ; const getters = { } ; const mutations = { tanksCleared ( state ) { state . error = false ; state . tanks = [ ] ; } , tanksLoaded ( state , tanks ) { state . error = false ; state . tanks = tanks ; } , tankError ( state ) { state . error = true ; state . tanks = [ ] ; } } ; export const tankStore = { namespaced , state , getters , actions , mutations } ;