import { ActionTree , GetterTree , Module , MutationTree } from 'vuex' ; import { IRootState } from '../store' ; import { User } from './types/user' ; import { UserService } from './userService' ; const namespaced = true ; export { User } ; export interface IUserState { users ? : User [ ] ; error : boolean ; } ; const state = { users : [ ] , error : false } ; const actions = { async clearCache ( { commit } ) { try { await UserService . clearCache ( ) ; commit ( 'userCleared' ) ; } catch ( error ) { commit ( 'userError' ) ; throw error ; } } , async fetchUsers ( { commit } ) { try { const users = await UserService . getUsers ( ) ; commit ( 'usersLoaded' , users ) ; } catch ( error ) { commit ( 'userError' ) ; throw error ; } } , } ; const getters = { } ; const mutations = { usersCleared ( state ) { state . error = false ; state . users = [ ] ; } , usersLoaded ( state , users ) { state . error = false ; state . users = users ; } , userError ( state ) { state . error = true ; state . users = [ ] ; } } ; export const userStore = { namespaced , state , getters , actions , mutations , } ;