2018-02-19 21:19:39 +00:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
2017-08-16 22:51:37 +00:00
|
|
|
import createSagaMiddleware from 'redux-saga';
|
2017-09-25 13:15:28 +00:00
|
|
|
import logger from 'redux-logger';
|
2017-09-21 17:08:00 +00:00
|
|
|
import { composeWithDevTools } from 'remote-redux-devtools';
|
2017-11-28 11:01:18 +00:00
|
|
|
import applyAppStateListener from 'redux-enhancer-react-native-appstate';
|
2017-08-17 06:28:41 +00:00
|
|
|
import reducers from '../reducers';
|
2017-08-17 00:24:06 +00:00
|
|
|
import sagas from '../sagas';
|
2017-08-13 01:35:09 +00:00
|
|
|
|
2017-08-16 22:51:37 +00:00
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
2017-09-21 17:08:00 +00:00
|
|
|
let enhacers;
|
2017-08-13 01:35:09 +00:00
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
/* eslint-disable global-require */
|
|
|
|
const reduxImmutableStateInvariant = require('redux-immutable-state-invariant').default();
|
2017-09-25 13:15:28 +00:00
|
|
|
|
2018-02-19 21:19:39 +00:00
|
|
|
const devComposer = composeWithDevTools({ hostname: 'localhost', port: 8000 });
|
|
|
|
enhacers = devComposer(
|
2017-11-28 11:01:18 +00:00
|
|
|
applyAppStateListener(),
|
2017-09-21 17:08:00 +00:00
|
|
|
applyMiddleware(reduxImmutableStateInvariant),
|
2017-09-25 13:15:28 +00:00
|
|
|
applyMiddleware(sagaMiddleware),
|
|
|
|
applyMiddleware(logger)
|
2017-09-21 17:08:00 +00:00
|
|
|
);
|
2017-08-13 01:35:09 +00:00
|
|
|
} else {
|
2018-02-19 21:19:39 +00:00
|
|
|
enhacers = compose(
|
2017-11-28 11:01:18 +00:00
|
|
|
applyAppStateListener(),
|
|
|
|
applyMiddleware(sagaMiddleware)
|
|
|
|
);
|
2017-08-13 01:35:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 20:08:31 +00:00
|
|
|
// uncomment the following lines to integrate reactotron with redux
|
|
|
|
// const store = Reactotron.createStore(
|
|
|
|
// reducers,
|
|
|
|
// enhacers(createStore)(reducers),
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
2017-09-21 17:08:00 +00:00
|
|
|
const store = enhacers(createStore)(reducers);
|
2017-08-17 00:24:06 +00:00
|
|
|
sagaMiddleware.run(sagas);
|
2017-09-21 17:08:00 +00:00
|
|
|
|
|
|
|
if (module.hot && typeof module.hot.accept === 'function') {
|
|
|
|
module.hot.accept(() => {
|
|
|
|
store.replaceReducer(require('../reducers').default);
|
|
|
|
sagaMiddleware.run(require('../sagas').default);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default store;
|