HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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);
            })
        }
    },
}