2017-06-24 01:26:08 +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';
|
2017-06-26 22:27:55 +00:00
|
|
|
import ensSaga from './sagas/ens';
|
2017-06-29 23:03:11 +00:00
|
|
|
import walletSaga from './sagas/wallet';
|
2017-07-05 22:09:58 +00:00
|
|
|
import { initialState as configInitialState } from 'reducers/config';
|
|
|
|
import throttle from 'lodash/throttle';
|
2017-04-12 05:04:27 +00:00
|
|
|
// application styles
|
2017-06-24 01:26:08 +00:00
|
|
|
import 'assets/styles/etherwallet-master.less';
|
2017-07-05 22:09:58 +00:00
|
|
|
import { saveState, loadStatePropertyOrEmptyObject } from 'utils/localStorage';
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-07-02 17:55:58 +00:00
|
|
|
let store;
|
2017-04-12 05:04:27 +00:00
|
|
|
|
|
|
|
const configureStore = () => {
|
2017-07-04 03:21:19 +00:00
|
|
|
const logger = createLogger({
|
|
|
|
collapsed: true
|
|
|
|
});
|
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
2017-06-24 01:26:08 +00:00
|
|
|
let middleware;
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
window.Perf = Perf;
|
2017-07-04 03:21:19 +00:00
|
|
|
middleware = composeWithDevTools(
|
|
|
|
applyMiddleware(sagaMiddleware, logger, routerMiddleware(history))
|
|
|
|
);
|
2017-06-24 01:26:08 +00:00
|
|
|
} else {
|
2017-07-04 03:21:19 +00:00
|
|
|
middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));
|
2017-06-24 01:26:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 22:09:58 +00:00
|
|
|
const persistedConfigInitialState = {
|
|
|
|
config: {
|
|
|
|
...configInitialState,
|
|
|
|
...loadStatePropertyOrEmptyObject('config')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const completePersistedInitialState = {
|
|
|
|
...persistedConfigInitialState
|
|
|
|
};
|
|
|
|
|
|
|
|
store = createStore(RootReducer, completePersistedInitialState, middleware);
|
2017-06-24 01:26:08 +00:00
|
|
|
sagaMiddleware.run(notificationsSaga);
|
2017-07-02 05:49:06 +00:00
|
|
|
sagaMiddleware.run(ensSaga);
|
2017-07-04 03:21:19 +00:00
|
|
|
sagaMiddleware.run(walletSaga);
|
2017-07-05 22:09:58 +00:00
|
|
|
|
|
|
|
store.subscribe(
|
|
|
|
throttle(() => {
|
|
|
|
saveState({
|
|
|
|
config: {
|
|
|
|
languageSelection: store.getState().config.languageSelection
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
1000
|
|
|
|
);
|
2017-06-24 01:26:08 +00:00
|
|
|
return store;
|
2017-04-12 05:04:27 +00:00
|
|
|
};
|
|
|
|
|
2017-06-24 01:26:08 +00:00
|
|
|
const renderRoot = Root => {
|
|
|
|
let store = configureStore();
|
|
|
|
let syncedHistory = syncHistoryWithStore(history, store);
|
|
|
|
render(
|
|
|
|
<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-07-03 18:23:44 +00:00
|
|
|
module.hot.accept('reducers/index', () =>
|
|
|
|
store.replaceReducer(require('reducers/index').default)
|
2017-07-02 17:55:58 +00:00
|
|
|
);
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|