MyCrypto/common/store.js
William O'Beirne e3505fd958 Contracts Tab Scaffolding (#70)
* Empty component, routes setup.

* Shared components for all Contracts inputs. Dont do anything yet.

* Check in reducer work so far. Still WIP.

* Header styling

* Check in input work so far, splitting to new branch.

* Strip down contracts inputs. Split out into form and explorer

* Contract selector

* Constantized config actions to use in contract saga.

* Interact explorer UI, no functionality

* Convert to constants, hook up errors

* Deploy and style cleanup.

* Remove unnecessary class.

* Fix flow errors with css modules

* Attempt at fixing all newly introduced flow errors in the contracts branch.

* Removed unused validator.

* Remove action constants, fix flow specificity in reducers

* Fix unit tests

* Move network contracts out of redux / sagas, and read directly from state with a selector in mapStateToProps.

* Fix initialState -> INITIAL_STATE rename

* foreach push -> concat
2017-07-27 19:31:59 -05:00

65 lines
1.8 KiB
JavaScript

import {
saveState,
loadState,
loadStatePropertyOrEmptyObject
} from 'utils/localStorage';
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
import sagas from './sagas';
import { INITIAL_STATE as configInitialState } from 'reducers/config';
import { INITIAL_STATE as customTokensInitialState } from 'reducers/customTokens';
import throttle from 'lodash/throttle';
import { composeWithDevTools } from 'redux-devtools-extension';
import Perf from 'react-addons-perf';
import { createStore, applyMiddleware } from 'redux';
import RootReducer from './reducers';
import { routerMiddleware } from 'react-router-redux';
const configureStore = () => {
const logger = createLogger({
collapsed: true
});
const sagaMiddleware = createSagaMiddleware();
let middleware;
let store;
if (process.env.NODE_ENV !== 'production') {
window.Perf = Perf;
middleware = composeWithDevTools(
applyMiddleware(sagaMiddleware, logger, routerMiddleware(history))
);
} else {
middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));
}
const persistedInitialState = {
config: {
...configInitialState,
...loadStatePropertyOrEmptyObject('config')
},
customTokens: (loadState() || {}).customTokens || customTokensInitialState
};
store = createStore(RootReducer, persistedInitialState, middleware);
// Add all of the sagas to the middleware
Object.keys(sagas).forEach(saga => {
sagaMiddleware.run(sagas[saga]);
});
store.subscribe(
throttle(() => {
saveState({
config: {
languageSelection: store.getState().config.languageSelection
},
customTokens: store.getState().customTokens
});
}),
1000
);
return store;
};
export const store = configureStore();