vn-verdnaturachat/app/lib/createStore.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-03-23 16:55:40 +00:00
import { createStore as reduxCreateStore, applyMiddleware, compose } from 'redux';
2017-08-16 22:51:37 +00:00
import createSagaMiddleware from 'redux-saga';
import logger from 'redux-logger';
import applyAppStateListener from 'redux-enhancer-react-native-appstate';
2018-03-23 16:55:40 +00:00
import Reactotron from 'reactotron-react-native'; // eslint-disable-line
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
2018-03-23 16:55:40 +00:00
const createStore = __DEV__ ? Reactotron.createStore : reduxCreateStore;
let sagaMiddleware;
let enhancers;
2017-08-13 01:35:09 +00:00
if (__DEV__) {
/* eslint-disable global-require */
const reduxImmutableStateInvariant = require('redux-immutable-state-invariant').default();
2018-03-23 16:55:40 +00:00
sagaMiddleware = createSagaMiddleware({
sagaMonitor: Reactotron.createSagaMonitor()
});
2018-03-23 16:55:40 +00:00
enhancers = compose(
applyAppStateListener(),
applyMiddleware(reduxImmutableStateInvariant),
applyMiddleware(sagaMiddleware),
applyMiddleware(logger)
);
2017-08-13 01:35:09 +00:00
} else {
2018-03-23 16:55:40 +00:00
sagaMiddleware = createSagaMiddleware();
enhancers = compose(
applyAppStateListener(),
applyMiddleware(sagaMiddleware)
);
2017-08-13 01:35:09 +00:00
}
2018-03-23 16:55:40 +00:00
const store = createStore(reducers, enhancers);
2017-08-17 00:24:06 +00:00
sagaMiddleware.run(sagas);
if (module.hot && typeof module.hot.accept === 'function') {
module.hot.accept(() => {
store.replaceReducer(require('../reducers').default);
sagaMiddleware.run(require('../sagas').default);
});
}
export default store;