Skip to content

Commit 6f06ae2

Browse files
committed
refactor(*): upgrade react-router-redux v3 to v4 (adapt api changes)
Some breaking changes in the API of react-router-redux between v3 & v4 fixed - more on dvdzkwsk/react-redux-starter-kit@0df26907 Also upgraded following deps: react-redux ^4.1.2 → ^4.4.5 react-router ^2.0.0 → ^2.2.4 redux ^3.1.7 → ^3.4.0 redux-devtools ^3.0.2 → ^3.2.0
1 parent 43690a9 commit 6f06ae2

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@
121121
"lscache": "^1.0.5",
122122
"react": "^0.14.7",
123123
"react-dom": "^0.14.7",
124-
"react-redux": "~4.1.2",
125-
"react-router": "^2.0.0",
126-
"react-router-redux": "^3.0.0",
127-
"redux": "~3.1.7",
128-
"redux-devtools": "~3.0.2",
124+
"react-redux": "^4.1.2",
125+
"react-router": "^2.2.4",
126+
"react-router-redux": "^4.0.2",
127+
"redux": "^3.1.7",
128+
"redux-devtools": "^3.0.2",
129129
"redux-devtools-dock-monitor": "^1.0.1",
130130
"redux-devtools-log-monitor": "^1.0.1",
131131
"superagent": "^1.7.2",

src/bootstrap.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import ReactDOM from 'react-dom';
55

66
import { Router, hashHistory } from 'react-router';
7+
import { syncHistoryWithStore } from 'react-router-redux';
78
import { Provider } from 'react-redux';
89

910
import routes from './routes.js';
@@ -14,28 +15,25 @@ import configureStore from './redux/configure-store.js';
1415
import httpService from './services/httpService.js';
1516
httpService.getInstance();
1617

18+
const initialState = {};
19+
20+
/**
21+
* The whole store/reducers/actions creators configuration is done inside configureStore
22+
*/
23+
const store = configureStore(initialState);
24+
1725
/**
1826
* Router initialization
19-
* react-router-redux config is done in configure-store
20-
* If you switch from hashHistory to another, please update configure-store.js
27+
* API has changed since react-router-redux v4 - checkout this commit for migration v3 -> v4: https://github.com/davezuko/react-redux-starter-kit/commit/0df26907
2128
*/
29+
const syncedHistory = syncHistoryWithStore(hashHistory, store);
2230

2331
const component = (
24-
<Router history={hashHistory}>
32+
<Router history={syncedHistory}>
2533
{routes}
2634
</Router>
2735
);
2836

29-
const initialState = {};
30-
31-
/**
32-
* The whole store/reducers/actions creators configuration is done inside configureStore
33-
* The configuration of the router is also done their since it's stored in redux store (using a specific reducer)
34-
*/
35-
const store = configureStore(initialState);
36-
37-
let rootElement = null;
38-
3937
/**
4038
* The linter can be disabled via DISABLE_LINTER env var - show a message in console to inform if it's on or off
4139
* Won't show in production
@@ -49,6 +47,8 @@ if (process.env.NODE_ENV !== 'production') {
4947
}
5048
}
5149

50+
let rootElement = null;
51+
5252
/**
5353
* Thanks to webpack.DefinePlugin which lets you inject variables at transpile time,
5454
* everything inside the if statement will be dropped at minification if process.env.DEVTOOLS is set to false.

src/redux/configure-store.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44
* I added some comments to help understand the code
55
*/
66

7-
import { hashHistory } from 'react-router';// using the same as the one in bootstrap.js @todo find a way to inject it ?
87
import { createStore, compose, applyMiddleware } from 'redux';
9-
import { syncHistory } from 'react-router-redux';
108

119
import clientMiddleware from './middleware/clientMiddleware';
1210

13-
/**
14-
* react-redux-router middleware setup
15-
*/
16-
const reduxRouterMiddleware = syncHistory(hashHistory);
17-
1811
/**
1912
* https://github.com/rackt/redux/blob/master/docs/Glossary.md#store-enhancer
2013
* Higher order function that compose a store creator and returns a new one: (StoreCreator) => (StoreCreator)
@@ -35,7 +28,7 @@ if (process.env.DEVTOOLS) {
3528
*/
3629
const combinedCreateStore = compose(...storeEnhancers)(createStore);
3730

38-
const middlewares = [clientMiddleware, reduxRouterMiddleware];
31+
const middlewares = [clientMiddleware];
3932

4033
if (process.env.DEVTOOLS) {
4134
middlewares.push(require('./middleware/logger'));
@@ -64,10 +57,6 @@ export default function configureStore(initialState) {
6457
*/
6558
const store = finalCreateStore(rootReducer, initialState);
6659

67-
if (process.env.DEVTOOLS) {
68-
reduxRouterMiddleware.listenForReplays(store);
69-
}
70-
7160
if (module.hot) {
7261
// Enable Webpack hot module replacement for reducers
7362
module.hot.accept('./modules/reducer', () => {

src/redux/modules/reducer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { combineReducers } from 'redux';
2-
import { routeReducer } from 'react-router-redux';// the middleware part configuration of react-redux-router is done in configure-store.js
2+
import { routerReducer as routing } from 'react-router-redux';
33

44
// reducers specific to app logic - to see an annotated reducer, open src/redux/modules/multipleUsers.js
55
import counter from './counter.js';
@@ -11,7 +11,7 @@ import singleUser from './singleUser.js';
1111
* (including the reducer of the router, since we use redux-router and so the state of the router is in the store)
1212
*/
1313
export default combineReducers({
14-
routing: routeReducer,
14+
routing,
1515
counter,
1616
multipleUsers,
1717
singleUser

0 commit comments

Comments
 (0)