import { SET_CURRENCIES, SET_LOADING_CURRENCIES } from '@/constants/mutationTypes' import { INIT_CURRENCIES, RESET_CURRENCY } from '@/constants/actionTypes' const initialState = { currencies: [], loadingCurrencies: false } const state = { currencies: initialState.currencies, loadingCurrencies: !initialState.currencies } const getters = { /** * * @param {*} state */ currencies(state) { return state.currencies }, /** * * @param {*} state */ loadingCurrencies(state) { return state.loadingCurrencies } } const mutations = { /** * * @param {*} state * @param {*} payload */ [SET_CURRENCIES] (state, payload) { state.currencies = payload }, /** * * @param {*} state * @param {*} payload */ [SET_LOADING_CURRENCIES] (state, payload) { state.loadingCurrencies = !!payload } } const actions = { /** * * @param {*} param0 * @param {*} payload */ [INIT_CURRENCIES] ({ commit }, payload) { commit(SET_CURRENCIES, payload) commit(SET_LOADING_CURRENCIES) }, /** * * @param {*} param0 * @param {*} payload */ [RESET_CURRENCY] ({ commit }) { commit(SET_LOADING_CURRENCIES, true) commit(SET_CURRENCIES, []) } } export default { state, getters, mutations, actions }