Skip to content

Commit 66875a1

Browse files
committed
clean up the mess
1 parent e9c76b5 commit 66875a1

File tree

4 files changed

+22
-47
lines changed

4 files changed

+22
-47
lines changed

src/client/index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import React from 'react';
2-
// import createHistory from 'history/createBrowserHistory';
2+
import createHistory from 'history/createBrowserHistory';
33
import { hydrate } from 'react-dom';
44
import { Provider } from 'react-redux';
5-
import { ConnectedRouter as Router } from 'react-router-redux';
5+
import { ConnectedRouter as Router, routerMiddleware } from 'react-router-redux';
66
import App from '../shared/App';
77
import IntlProvider from '../shared/i18n/IntlProvider';
8-
// import { configureStore } from '../shared/store';
9-
import { store, history } from '../shared/store';
8+
import { configureStore } from '../shared/store';
109

11-
// const history = createHistory();
12-
// const store = configureStore({
13-
// initialState: window.__PRELOADED_STATE__,
14-
// middleware: [routerMiddleware(history)],
15-
// });
10+
const browserHistory = window.browserHistory || createHistory();
11+
const store =
12+
window.store ||
13+
configureStore({
14+
initialState: window.__PRELOADED_STATE__,
15+
middleware: [routerMiddleware(history)],
16+
});
1617

1718
hydrate(
1819
<Provider store={store}>
19-
<Router history={history}>
20+
<Router history={browserHistory}>
2021
<IntlProvider>
2122
<App />
2223
</IntlProvider>
@@ -25,6 +26,13 @@ hydrate(
2526
document.getElementById('app')
2627
);
2728

28-
if (module.hot) {
29-
module.hot.accept();
29+
if (process.env.NODE_ENV === 'development') {
30+
if (module.hot) {
31+
module.hot.accept();
32+
}
33+
34+
if (!window.store || !window.browserHistory) {
35+
window.browserHistory = browserHistory;
36+
window.store = store;
37+
}
3038
}

src/server/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ require('dotenv').config();
1313

1414
const app = express();
1515

16+
// Use nginx or Apache to serve static assets in production or remove the if() around the following
17+
// lines to use the express.static middleware to serve assets for production (not recommended!)
1618
if (process.env.NODE_ENV === 'development') {
1719
app.use(paths.publicPath, express.static(paths.clientBuild));
1820
app.use('/favicon.ico', (req, res) => {

src/shared/store/index.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import thunk from 'redux-thunk';
22
import { createStore, applyMiddleware, compose } from 'redux';
33
import rootReducer from './rootReducer';
4-
import isClient from 'shared/utils/isClient';
54

65
export const configureStore = ({ initialState, middleware = [] } = {}) => {
7-
if (isClient() && window.store) {
8-
return window.store;
9-
}
10-
116
const devtools =
127
typeof window !== 'undefined' &&
138
typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function' &&
@@ -21,10 +16,6 @@ export const configureStore = ({ initialState, middleware = [] } = {}) => {
2116
composeEnhancers(applyMiddleware(...[thunk].concat(...middleware)))
2217
);
2318

24-
if (isClient()) {
25-
window.store = store;
26-
}
27-
2819
if (process.env.NODE_ENV !== 'production') {
2920
if (module.hot) {
3021
module.hot.accept('./rootReducer', () =>
@@ -37,22 +28,3 @@ export const configureStore = ({ initialState, middleware = [] } = {}) => {
3728
};
3829

3930
export default configureStore;
40-
41-
export let store;
42-
export let history;
43-
44-
if (isClient()) {
45-
const createHistory = require('history/createBrowserHistory').default;
46-
const { routerMiddleware } = require('react-router-redux');
47-
48-
if (window.browserHistory) {
49-
history = window.browserHistory;
50-
} else {
51-
history = createHistory();
52-
}
53-
54-
store = configureStore({
55-
initialState: window.__PRELOADED_STATE__,
56-
middleware: [routerMiddleware(history)],
57-
});
58-
}

src/shared/utils/isClient.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)