MyCrypto/common/index.jsx

56 lines
1.7 KiB
React
Raw Normal View History

2017-06-26 22:27:55 +00:00
import React from 'react';
import { render } from 'react-dom';
import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import Perf from 'react-addons-perf';
import { createStore, applyMiddleware } from 'redux';
import RootReducer from './reducers';
import { Root } from 'components';
import { Routing, history } from './routing';
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
import notificationsSaga from './sagas/notifications';
import ensSaga from './sagas/ens';
2017-04-14 06:23:36 +00:00
2017-04-12 05:04:27 +00:00
// application styles
2017-06-26 22:27:55 +00:00
import 'assets/styles/etherwallet-master.less';
2017-04-12 05:04:27 +00:00
2017-06-26 22:27:55 +00:00
const sagaMiddleware = createSagaMiddleware();
2017-04-12 05:04:27 +00:00
const configureStore = () => {
2017-06-21 23:31:59 +00:00
let sagaApplied = applyMiddleware(sagaMiddleware);
2017-04-14 06:23:36 +00:00
let store;
let middleware;
2017-04-12 05:04:27 +00:00
if (process.env.NODE_ENV !== 'production') {
2017-04-14 06:23:36 +00:00
window.Perf = Perf;
2017-06-21 23:31:59 +00:00
sagaApplied = composeWithDevTools(sagaApplied);
2017-04-14 06:23:36 +00:00
const logger = createLogger({
collapsed: true
});
middleware = applyMiddleware(routerMiddleware(history), logger);
} else {
middleware = applyMiddleware(routerMiddleware(history));
2017-04-12 05:04:27 +00:00
}
2017-04-14 06:23:36 +00:00
2017-06-21 23:31:59 +00:00
store = createStore(RootReducer, sagaApplied, middleware);
2017-06-26 22:27:55 +00:00
sagaMiddleware.run(notificationsSaga);
sagaMiddleware.run(ensSaga);
return store;
2017-04-12 05:04:27 +00:00
};
2017-06-26 22:27:55 +00:00
const renderRoot = Root => {
2017-04-12 05:04:27 +00:00
let store = configureStore();
let syncedHistory = syncHistoryWithStore(history, store);
render(
2017-06-26 22:27:55 +00:00
<Root key={Math.random()} routes={Routing} history={syncedHistory} store={store} />,
document.getElementById('app')
);
2017-04-12 05:04:27 +00:00
};
renderRoot(Root);
if (module.hot) {
2017-06-26 22:27:55 +00:00
module.hot.accept();
2017-04-12 05:04:27 +00:00
}