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

Commit 0574e4d

Browse files
committed
Merge pull request #218 from stepankuzmin/master
Support ImmutableJS: use getLocationState instead of getRouterState as mentioned in #140
2 parents 93bf238 + 22db2bb commit 0574e4d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ _Have an example to add? Send us a PR!_
131131

132132
Call this to create a middleware that can be applied with Redux's `applyMiddleware` to allow actions to call history methods. The middleware will look for route actions created by `push`, `replace`, etc. and applies them to the history.
133133

134-
#### `ReduxMiddleware.listenForReplays(store: ReduxStore, selectRouterState?: function)`
134+
#### `ReduxMiddleware.listenForReplays(store: ReduxStore, selectLocationState?: function)`
135135

136136
By default, the syncing logic will not respond to replaying of actions, which means it won't work with projects like redux-devtools. Call this function on the middleware object returned from `syncHistory` and give it the store to listen to, and it will properly work with action replays. Obviously, you would do that after you have created the store and everything else has been set up.
137137

138-
Supply an optional function `selectRouterState` to customize where to find the router state on your app state. It defaults to `state => state.routing`, so you would install the reducer under the name "routing". Feel free to change this to whatever you like.
138+
Supply an optional function `selectLocationState` to customize where to find the location state on your app state. It defaults to `state => state.routing.location`, so you would install the reducer under the name "routing". Feel free to change this to whatever you like.
139139

140140
#### `ReduxMiddleware.unsubscribe()`
141141

src/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export const TRANSITION = '@@router/TRANSITION'
44
export const UPDATE_LOCATION = '@@router/UPDATE_LOCATION'
55

6-
const SELECT_STATE = state => state.routing
6+
const SELECT_LOCATION = state => state.routing.location
77

88
function transition(method) {
99
return arg => ({
@@ -71,12 +71,12 @@ export function syncHistory(history) {
7171
}
7272

7373
middleware.listenForReplays =
74-
(store, selectRouterState = SELECT_STATE) => {
75-
const getRouterState = () => selectRouterState(store.getState())
76-
const { location: initialLocation } = getRouterState()
74+
(store, selectLocationState = SELECT_LOCATION) => {
75+
const getLocationState = () => selectLocationState(store.getState())
76+
const initialLocation = getLocationState()
7777

7878
unsubscribeStore = store.subscribe(() => {
79-
const { location } = getRouterState()
79+
const location = getLocationState()
8080

8181
// If we're resetting to the beginning, use the saved initial value. We
8282
// need to dispatch a new action at this point to populate the store

0 commit comments

Comments
 (0)