Skip to content

Commit

Permalink
clean up the mess
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbieh committed May 18, 2018
1 parent e9c76b5 commit 66875a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 47 deletions.
32 changes: 20 additions & 12 deletions src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import React from 'react';
// import createHistory from 'history/createBrowserHistory';
import createHistory from 'history/createBrowserHistory';
import { hydrate } from 'react-dom';
import { Provider } from 'react-redux';
import { ConnectedRouter as Router } from 'react-router-redux';
import { ConnectedRouter as Router, routerMiddleware } from 'react-router-redux';
import App from '../shared/App';
import IntlProvider from '../shared/i18n/IntlProvider';
// import { configureStore } from '../shared/store';
import { store, history } from '../shared/store';
import { configureStore } from '../shared/store';

// const history = createHistory();
// const store = configureStore({
// initialState: window.__PRELOADED_STATE__,
// middleware: [routerMiddleware(history)],
// });
const browserHistory = window.browserHistory || createHistory();
const store =
window.store ||
configureStore({
initialState: window.__PRELOADED_STATE__,
middleware: [routerMiddleware(history)],
});

hydrate(
<Provider store={store}>
<Router history={history}>
<Router history={browserHistory}>
<IntlProvider>
<App />
</IntlProvider>
Expand All @@ -25,6 +26,13 @@ hydrate(
document.getElementById('app')
);

if (module.hot) {
module.hot.accept();
if (process.env.NODE_ENV === 'development') {
if (module.hot) {
module.hot.accept();
}

if (!window.store || !window.browserHistory) {
window.browserHistory = browserHistory;
window.store = store;
}
}
2 changes: 2 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require('dotenv').config();

const app = express();

// Use nginx or Apache to serve static assets in production or remove the if() around the following
// lines to use the express.static middleware to serve assets for production (not recommended!)
if (process.env.NODE_ENV === 'development') {
app.use(paths.publicPath, express.static(paths.clientBuild));
app.use('/favicon.ico', (req, res) => {
Expand Down
28 changes: 0 additions & 28 deletions src/shared/store/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import thunk from 'redux-thunk';
import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from './rootReducer';
import isClient from 'shared/utils/isClient';

export const configureStore = ({ initialState, middleware = [] } = {}) => {
if (isClient() && window.store) {
return window.store;
}

const devtools =
typeof window !== 'undefined' &&
typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function' &&
Expand All @@ -21,10 +16,6 @@ export const configureStore = ({ initialState, middleware = [] } = {}) => {
composeEnhancers(applyMiddleware(...[thunk].concat(...middleware)))
);

if (isClient()) {
window.store = store;
}

if (process.env.NODE_ENV !== 'production') {
if (module.hot) {
module.hot.accept('./rootReducer', () =>
Expand All @@ -37,22 +28,3 @@ export const configureStore = ({ initialState, middleware = [] } = {}) => {
};

export default configureStore;

export let store;
export let history;

if (isClient()) {
const createHistory = require('history/createBrowserHistory').default;
const { routerMiddleware } = require('react-router-redux');

if (window.browserHistory) {
history = window.browserHistory;
} else {
history = createHistory();
}

store = configureStore({
initialState: window.__PRELOADED_STATE__,
middleware: [routerMiddleware(history)],
});
}
7 changes: 0 additions & 7 deletions src/shared/utils/isClient.js

This file was deleted.

0 comments on commit 66875a1

Please sign in to comment.