2018-01-29 20:47:12 +01:00
|
|
|
import React from 'react';
|
2018-02-21 22:42:41 +01:00
|
|
|
import { hydrate } from 'react-dom';
|
2018-02-20 23:31:05 +01:00
|
|
|
import { Provider } from 'react-redux';
|
2018-02-07 04:00:52 +01:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
2018-02-20 23:31:05 +01:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2018-01-29 20:47:12 +01:00
|
|
|
import Reducer from 'reducers';
|
2018-02-07 04:00:52 +01:00
|
|
|
import createSagaMiddleware from 'redux-saga';
|
|
|
|
import rootSaga from 'sagas';
|
2018-02-20 23:31:05 +01:00
|
|
|
|
2018-03-15 23:59:05 +01:00
|
|
|
import GAListener from 'components/GAListener';
|
2018-02-20 23:31:05 +01:00
|
|
|
import App from './app';
|
2018-01-29 20:47:12 +01:00
|
|
|
|
2018-02-21 17:05:41 +01:00
|
|
|
// get the state from a global variable injected into the server-generated HTML
|
|
|
|
const preloadedState = window.__PRELOADED_STATE__ || null;
|
|
|
|
|
|
|
|
// Allow the passed state to be garbage-collected
|
2018-02-22 02:02:57 +01:00
|
|
|
delete window.__PRELOADED_STATE__;
|
2018-02-21 17:05:41 +01:00
|
|
|
|
|
|
|
// create and apply middleware
|
2018-02-07 04:00:52 +01:00
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
|
|
|
const middleware = applyMiddleware(sagaMiddleware);
|
2018-02-21 17:05:41 +01:00
|
|
|
const reduxMiddleware = window.__REDUX_DEVTOOLS_EXTENSION__ ? compose(middleware, window.__REDUX_DEVTOOLS_EXTENSION__()) : middleware;
|
2018-02-07 04:00:52 +01:00
|
|
|
|
2018-02-21 17:05:41 +01:00
|
|
|
// create teh store
|
2018-02-21 19:53:36 +01:00
|
|
|
let store;
|
|
|
|
if (preloadedState) {
|
|
|
|
store = createStore(Reducer, preloadedState, reduxMiddleware);
|
|
|
|
} else {
|
|
|
|
store = createStore(Reducer, reduxMiddleware);
|
|
|
|
}
|
2018-01-29 20:47:12 +01:00
|
|
|
|
2018-02-21 17:05:41 +01:00
|
|
|
// run the saga middlweare
|
2018-02-07 04:00:52 +01:00
|
|
|
sagaMiddleware.run(rootSaga);
|
|
|
|
|
2018-02-21 17:05:41 +01:00
|
|
|
// render the app
|
2018-02-21 22:42:41 +01:00
|
|
|
hydrate(
|
2018-02-20 23:31:05 +01:00
|
|
|
<Provider store={store}>
|
|
|
|
<BrowserRouter>
|
|
|
|
<GAListener>
|
|
|
|
<App />
|
|
|
|
</GAListener>
|
|
|
|
</BrowserRouter>
|
|
|
|
</Provider>,
|
2018-01-29 20:47:12 +01:00
|
|
|
document.getElementById('react-app')
|
2018-01-29 21:49:01 +01:00
|
|
|
);
|