diff --git a/CHANGELOG.md b/CHANGELOG.md index e7293b3629..7506c7746c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed / Improved - Optimized `translation.processor` to process only enabled locale CSV files - @pkarw (#3950) +- Remove commit register mapping - @gibkigonzo (#3875) ## [1.11.0] - 2019.12.20 diff --git a/core/modules/url/store/actions.ts b/core/modules/url/store/actions.ts index 8cac1ff8ad..e1c9714c29 100644 --- a/core/modules/url/store/actions.ts +++ b/core/modules/url/store/actions.ts @@ -1,6 +1,5 @@ import { UrlState } from '../types/UrlState' import { ActionTree } from 'vuex'; -import * as types from './mutation-types' // you can use this storage if you want to enable offline capabilities import { cacheStorage } from '../' import queryString from 'query-string' @@ -13,8 +12,10 @@ import storeCodeFromRoute from '@vue-storefront/core/lib/storeCodeFromRoute' // it's a good practice for all actions to return Promises with effect of their execution export const actions: ActionTree = { // if you want to use cache in your module you can load cached data like this - async registerMapping ({ commit }, { url, routeData }: { url: string, routeData: any}) { - commit(types.REGISTER_MAPPING, { url, routeData }) + async registerMapping ({ state }, { url, routeData }: { url: string, routeData: any}) { + if (!state.dispatcherMap[url]) { + state.dispatcherMap[url] = routeData + } try { await cacheStorage.setItem(normalizeUrlPath(url), routeData, null, config.seo.disableUrlRoutesPersistentCache) } catch (err) { diff --git a/core/modules/url/store/index.ts b/core/modules/url/store/index.ts index 336bade112..025bdb3013 100644 --- a/core/modules/url/store/index.ts +++ b/core/modules/url/store/index.ts @@ -1,12 +1,10 @@ import { Module } from 'vuex' import { UrlState } from '../types/UrlState' -import { mutations } from './mutations' import { actions } from './actions' import { state } from './state' export const urlStore: Module = { namespaced: true, - mutations, actions, state } diff --git a/core/modules/url/store/mutation-types.ts b/core/modules/url/store/mutation-types.ts deleted file mode 100644 index 5f047c63b8..0000000000 --- a/core/modules/url/store/mutation-types.ts +++ /dev/null @@ -1 +0,0 @@ -export const REGISTER_MAPPING = 'URL/REGISTER_MAPPING' diff --git a/core/modules/url/store/mutations.ts b/core/modules/url/store/mutations.ts deleted file mode 100644 index ed2a7a8027..0000000000 --- a/core/modules/url/store/mutations.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { MutationTree } from 'vuex' -import * as types from './mutation-types' - -export const mutations: MutationTree = { - [types.REGISTER_MAPPING] (state, payload) { - state.dispatcherMap = Object.assign({}, state.dispatcherMap, { [payload.url]: payload.routeData }) - } -} diff --git a/core/modules/url/test/unit/store/actions.spec.ts b/core/modules/url/test/unit/store/actions.spec.ts index 454b417fdf..278bd74b82 100644 --- a/core/modules/url/test/unit/store/actions.spec.ts +++ b/core/modules/url/test/unit/store/actions.spec.ts @@ -1,4 +1,3 @@ -import * as types from '@vue-storefront/core/modules/url/store/mutation-types'; import { cacheStorage } from '@vue-storefront/core/modules/recently-viewed/index'; import { actions as urlActions } from '../../../store/actions'; import { currentStoreView, localizedDispatcherRouteName } from '@vue-storefront/core/lib/multistore'; @@ -75,17 +74,15 @@ describe('Url actions', () => { describe('registerMapping action', () => { it('should call register mapping mutation', async () => { const contextMock = { - commit: jest.fn() + state: { + dispatcherMap: {} + } }; const result = await (urlActions as any).registerMapping(contextMock, { url, routeData }); - expect(contextMock.commit).toHaveBeenCalledWith(types.REGISTER_MAPPING, { - url, - routeData - }); expect(result).toEqual(routeData); }); }); diff --git a/core/modules/url/test/unit/store/mutations.spec.ts b/core/modules/url/test/unit/store/mutations.spec.ts deleted file mode 100644 index 4f890d3a31..0000000000 --- a/core/modules/url/test/unit/store/mutations.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as types from '../../../store/mutation-types' -import { mutations as urlMutations } from '../../../store/mutations' - -describe('url mutations', () => { - beforeEach(() => { - jest.clearAllMocks() - }) - - describe('REGISTER_MAPPING', () => { - it('should register mapping', () => { - const stateMock = { - dispatcherMap: {} - } - const payloadData = { - url: 'https://www.example.com', - routeData: {name: 'example'} - } - const expectedState = { - dispatcherMap: { - 'https://www.example.com': {name: 'example'} - } - } - const wrapper = (mutations: any) => mutations[types.REGISTER_MAPPING](stateMock, payloadData) - - wrapper(urlMutations) - - expect(stateMock).toEqual(expectedState) - }) - }) -})