UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

5 lines 854 B
import{historyPop}from"./historyPop";import{mutable}from"../../helpers/redux";import{getRouterStackIndex,makeGetPrevRouteIndexByPattern}from"../../selectors/router";/** * @mixes {MutableFunction} * @param {Object} [params={}] The history params. * @return {Function} The dispatched action. */export var historyPopToRoute=mutable(function(_ref){var pattern=_ref.pattern,routeId=_ref.routeId;return function(dispatch,getState){var state=getState();var getPrevRouteIndexByPatternCart=makeGetPrevRouteIndexByPattern(pattern);var nextRouteIndex=getPrevRouteIndexByPatternCart(state,{routeId:routeId});var currentRouteIndex=getRouterStackIndex(state,{routeId:routeId});if(currentRouteIndex===null||nextRouteIndex===null||nextRouteIndex===-1){dispatch(historyPop());}else{var steps=currentRouteIndex-nextRouteIndex;dispatch(historyPop({steps:steps}));}};});