File: D:/HostingSpaces/SBogers10/shop.komma.nl/resources/js/store/modules/modules/regionInfo.js
import { G11nService } from '../../../../../vendor/komma/kms/resources/js/global/g11nService';
import Vue from 'vue';
const g11nService = new G11nService();
export default {
namespaced: true,
state: {
requests: [],
specific: null,
neutral: null
},
mutations: {
loadSpecificRegionInfo(state, specificRegionInfo) {
if(state.specific) return; //Already loaded
Vue.set(state, 'specific', specificRegionInfo);
const requestKeyIndex = state.requests.indexOf('specific');
if(requestKeyIndex !== -1) state.requests.splice(requestKeyIndex, 1);
},
loadNeutralRegionInfo(state, neutralRegionInfo) {
if(state.neutral) return; //Already loaded
Vue.set(state, 'neutral', neutralRegionInfo);
const requestKeyIndex = state.requests.indexOf('neutral');
if(requestKeyIndex !== -1) state.requests.splice(requestKeyIndex, 1);
},
requestedSpecificRegionInfo(state) {
if(state.requests.indexOf('specific') !== -1) return; //Already loading
state.requests.push('specific');
},
requestedNeutralRegionInfo(state) {
if(state.requests.indexOf('neutral') !== -1) return; //Already loading
state.requests.push('neutral');
}
},
actions: {
loadSpecific({ commit, state }) {
if(state.requests.indexOf('specific') !== -1) return; //Already loading
commit('requestedSpecificRegionInfo');
g11nService.regionInfo.specific().then(regionInfo => commit('loadSpecificRegionInfo', regionInfo))
},
loadNeutral({ commit, state }) {
if(state.requests.indexOf('neutral') !== -1) return; //Already loading
commit('requestedNeutralRegionInfo');
g11nService.regionInfo.neutral().then(regionInfo => commit('loadNeutralRegionInfo', regionInfo)).catch(function(error) {
console.log('Vuex regionInfo module: could not get translation for key: ' + key, error);
})
}
},
}