UNPKG

@empathyco/x-components

Version:
37 lines (34 loc) 1.41 kB
import { getNewAndUpdatedKeys } from '@empathyco/x-utils'; import { isArrayEmpty } from '../../../../utils/array.js'; /** * Default implementation for the {@link SearchActions.resetRequestOnRefinement}. * * @param context - The {@link https://vuex.vuejs.org/guide/actions.html | context} of the actions, * provided by Vuex. * @param watchedRequest - The {@link WatchedInternalSearchRequest} object. * @public */ const resetRequestOnRefinement = ({ commit, state }, { newRequest, oldRequest }) => { if (state.fromNoResultsWithFilters && state.results.length) { commit('setFromNoResultsWithFilters', false); } // is refining request if (!!newRequest && !!oldRequest) { const changedKeys = getNewAndUpdatedKeys(newRequest, oldRequest).filter(value => value !== 'extraParams'); const changedExtraParams = getNewAndUpdatedKeys(newRequest.extraParams, oldRequest.extraParams); if (!isArrayEmpty(changedKeys)) { if (!changedKeys.includes('page')) { commit('setPage', 1); } if (changedKeys.includes('query')) { commit('setSort', ''); } } if (!isArrayEmpty(changedExtraParams)) { commit('setPage', 1); commit('setSort', ''); } } }; export { resetRequestOnRefinement }; //# sourceMappingURL=reset-request-on-refinement.action.js.map