import { ActionTree, Module, MutationTree } from 'vuex'; import RootState from '../types/RootStateModel'; import DataStoreModel from '../types/DataStoreModel'; import DataApi from '../../api/data-api'; import { DynamicValueTag } from '../../types/api'; const namespaced = true; const state: DataStoreModel = { dynamicTags: [] }; const actions: ActionTree = { async $init({ dispatch }) { dispatch('fetchDynamicTags'); }, async fetchDynamicTags({ commit }) { const tags = await DataApi.getDynamicTags(); commit('setDynamicTags', tags); } }; const mutations: MutationTree = { setDynamicTags(dataState, tags: DynamicValueTag[]) { dataState.dynamicTags = tags; } }; export const dataStore: Module = { namespaced, state, actions, mutations };