interface CountData {type: string, val: number}

const state = {
	countA: 0,
	countB: 0
}

const getters = {
	aSubB: (state: any) => {
		return state.countA - state.countB
	},
	stringASubB: (state: any, getters: any) => {
		return getters.aSubB === 0 ? 'A 等于 B' : (getters.aSubB > 0 ? 'A 大于 B' : 'B 大于 A')
	}
}

const mutations = {
	SET_COUNT(state: any, {type, val}: CountData) {
		state[type] = val ? val : state[type] + 1
	},
}

const actions = {
	LOAD_COUNT(context: any, data: CountData) {
		context.commit('SET_COUNT', data)
	}
}

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