23 lines
763 B
JavaScript
23 lines
763 B
JavaScript
|
import { createStore, applyMiddleware, compose } from "redux";
|
||
|
import createSagaMiddleware from "redux-saga";
|
||
|
import { createLogger } from "redux-logger";
|
||
|
import rootReducer from "../reducers";
|
||
|
import rootSaga from "../sagas";
|
||
|
|
||
|
export default function configureStore(initialState = {}) {
|
||
|
const sagaMiddleware = createSagaMiddleware();
|
||
|
const middlewares = [sagaMiddleware];
|
||
|
if (process.env.NODE_ENV === "development" && process.env.REACT_APP_REDUX_LOGGING) {
|
||
|
middlewares.push(createLogger());
|
||
|
}
|
||
|
|
||
|
const enhancers = [applyMiddleware(...middlewares)];
|
||
|
const store = createStore(rootReducer, initialState, compose(...enhancers));
|
||
|
|
||
|
// Extensions
|
||
|
store.asyncReducers = {}; // Async reducer registry
|
||
|
sagaMiddleware.run(rootSaga);
|
||
|
|
||
|
return store;
|
||
|
}
|