/
reducer.js
36 lines (28 loc) · 1.17 KB
/
reducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
exports.__esModule = true;
var _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; };
exports.routerReducer = routerReducer;
/**
* This action type will be dispatched when your history
* receives a location change.
*/
var LOCATION_CHANGE = exports.LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
var initialState = {
location: null
};
/**
* This reducer will update the state with the most recent location history
* has transitioned to. This may not be in sync with the router, particularly
* if you have asynchronously-loaded routes, so reading from and relying on
* this state is discouraged.
*/
function routerReducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
type = _ref.type,
payload = _ref.payload;
if (type === LOCATION_CHANGE) {
return _extends({}, state, { location: payload });
}
return state;
}