UNPKG

@shopgate/pwa-common-commerce

Version:

Commerce library for the Shopgate Connect PWA.

5 lines 1.01 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{historyReplace}from'@shopgate/pwa-common/actions/router';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{parseObjectToQueryString}from'@shopgate/pwa-common/helpers/router';/** * Updates the sort parameter in the history. * @param {string} sort The sort order * @returns {Function} A redux thunk. */var changeSortOrder=function changeSortOrder(sort){return function(dispatch,getState){var _getCurrentRoute=getCurrentRoute(getState()),query=_getCurrentRoute.query,state=_getCurrentRoute.state;var newQuery=parseObjectToQueryString(_extends({},query,{sort:sort}));dispatch(historyReplace({pathname:"".concat(window.location.pathname).concat(newQuery),state:state}));};};export default changeSortOrder;