UNPKG

mwc-test

Version:

## Project setup ``` yarn install ```

39 lines (33 loc) 898 B
import Vue from 'vue'; import Vuex from 'vuex'; import _ from 'lodash'; import loginModule from './modules/login'; Vue.use(Vuex); // actions with no Payload const actionMap = { toggleRememberMe: 'loginModule/toggleRememberMe', }; // mapper to actions with no payload function getAction(actionName) { return actionMap[actionName] || actionName; } export default new Vuex.Store({ state: {}, modules: { loginModule }, mutations: {}, actions: { dispatchAction({ dispatch }, payload) { if (typeof payload === 'string') { return dispatch(getAction(payload)); } const { actionName } = payload; if (!actionName) { throw new Error( 'dispatchAction payload must have an actionName property', ); } const newPayload = _.cloneDeep(payload.data); return dispatch(getAction(actionName), newPayload); }, }, });