-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathconfigureStore.ts
More file actions
32 lines (28 loc) · 1.46 KB
/
configureStore.ts
File metadata and controls
32 lines (28 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Store, createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
// `react-router-redux` is deprecated, so we use `connected-react-router`.
// This provides a Redux middleware which connects to our `react-router` instance.
import { routerMiddleware } from 'connected-react-router'
// We'll be using Redux Devtools. We can use the `composeWithDevTools()`
// directive so we can pass our middleware along with it
import { composeWithDevTools } from 'redux-devtools-extension'
// If you use react-router, don't forget to pass in your history type.
import { History } from 'history'
// Import the state interface and our combined reducers/sagas.
import { ApplicationState, createRootReducer, rootSaga } from './store'
export default function configureStore(history: History, initialState: ApplicationState): Store<ApplicationState> {
// create the composing function for our middlewares
const composeEnhancers = composeWithDevTools({})
// create the redux-saga middleware
const sagaMiddleware = createSagaMiddleware()
// We'll create our store with the combined reducers/sagas, and the initial Redux state that
// we'll be passing from our entry point.
const store = createStore(
createRootReducer(history),
// initialState,
composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware))
)
// Don't forget to run the root saga, and return the store object.
sagaMiddleware.run(rootSaga)
return store
}