mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 14:57:18 +10:00
30 lines
1 KiB
JavaScript
30 lines
1 KiB
JavaScript
/* eslint-disable no-underscore-dangle */
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
|
import createSagaMiddleware, { END } from 'redux-saga';
|
|
import thunk from 'redux-thunk';
|
|
import createReducer from './reducers';
|
|
|
|
/**
|
|
* Create a new store with the given initial state. Adds Redux
|
|
* middleware and enhancers.
|
|
*/
|
|
export default function configureStore(sdk, initialState = {}) {
|
|
const sagaMiddleware = createSagaMiddleware();
|
|
|
|
const middlewares = [thunk.withExtraArgument(sdk), sagaMiddleware];
|
|
|
|
// Enable Redux Devtools in client side dev mode.
|
|
const composeEnhancers = process.env.NODE_ENV !== 'production' &&
|
|
typeof window === 'object' &&
|
|
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
|
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
|
: compose;
|
|
|
|
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
|
|
|
|
const store = createStore(createReducer(), initialState, enhancer);
|
|
store.runSaga = sagaMiddleware.run;
|
|
store.closeSagaMiddleware = () => store.dispatch(END);
|
|
|
|
return store;
|
|
}
|