twreporter-react
Version:
React-Redux site for The Reporter Foundation in Taiwan
33 lines (27 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = routerMiddleware;
var _actions = require('./actions');
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**
* This middleware captures CALL_HISTORY_METHOD actions to redirect to the
* provided history object. This will prevent these actions from reaching your
* reducer or any middleware that comes after this one.
*/
function routerMiddleware(history) {
return function () {
return function (next) {
return function (action) {
if (action.type !== _actions.CALL_HISTORY_METHOD) {
return next(action);
}
var _action$payload = action.payload;
var method = _action$payload.method;
var args = _action$payload.args;
history[method].apply(history, _toConsumableArray(args));
};
};
};
}