Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit 88bc0de

Browse files
committed
Minor reorg. Split the reducer to its own file.
1 parent fbe174f commit 88bc0de

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
lib
22
node_modules
33
coverage
4+
*.log

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
export syncHistoryWithStore from './sync'
2+
export { LOCATION_CHANGE, routerReducer } from './reducer'
3+
14
export {
25
UPDATE_LOCATION,
36
push, replace, go, goBack, goForward,
47
routeActions
58
} from './actions'
6-
79
export routerMiddleware from './middleware'
8-
9-
export { LOCATION_CHANGE, routerReducer, syncHistoryWithStore } from './sync'

src/reducer.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* This action type will be dispatched when your history
3+
* receives a location change.
4+
*/
5+
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE'
6+
7+
const initialState = {
8+
locationBeforeTransitions: null
9+
}
10+
11+
/**
12+
* This reducer will update the state with the most recent location history
13+
* has transitioned to. This may not be in sync with the router, particularly
14+
* if you have asynchronously-loaded routes, so reading from and relying on
15+
* this state it is discouraged.
16+
*/
17+
export function routerReducer(state = initialState, { type, locationBeforeTransitions }) {
18+
if (type === LOCATION_CHANGE) {
19+
return { ...state, locationBeforeTransitions }
20+
}
21+
22+
return state
23+
}

src/sync.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
/**
2-
* This action type will be dispatched when your history
3-
* receives a location change.
4-
*/
5-
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE'
6-
7-
const initialState = {
8-
locationBeforeTransitions: null
9-
}
1+
import { LOCATION_CHANGE } from './reducer'
102

113
const defaultSelectLocationState = state => state.routing
124

13-
/**
14-
* This reducer will update the state with the most recent location history
15-
* has transitioned to. This may not be in sync with the router, particularly
16-
* if you have asynchronously-loaded routes, so reading from and relying on
17-
* this state it is discouraged.
18-
*/
19-
export function routerReducer(state = initialState, { type, locationBeforeTransitions }) {
20-
if (type === LOCATION_CHANGE) {
21-
return { ...state, locationBeforeTransitions }
22-
}
23-
24-
return state
25-
}
26-
275
/**
286
* This function synchronizes your history state with the Redux store.
297
* Location changes flow from history to the store. An enhanced history is
@@ -36,7 +14,7 @@ export function routerReducer(state = initialState, { type, locationBeforeTransi
3614
* event, the router will be updated appropriately and can transition to the
3715
* correct router state.
3816
*/
39-
export function syncHistoryWithStore(history, store, {
17+
export default function syncHistoryWithStore(history, store, {
4018
selectLocationState = defaultSelectLocationState,
4119
adjustUrlOnReplay = true
4220
} = {}) {

0 commit comments

Comments
 (0)