-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
38 lines (30 loc) · 1.11 KB
/
store.js
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
33
34
35
36
37
38
import { createStore, applyMiddleware, compose } from 'redux'
import withRedux from 'next-redux-wrapper'
import Immutable from 'seamless-immutable'
import nextReduxSaga from 'next-redux-saga'
import createSagaMiddleware from 'redux-saga'
import rootReducer from './reducers'
import rootSaga from './sagas'
const sagaMiddleware = createSagaMiddleware()
const dev = process.env.NODE_ENV !== 'production'
const windowExist = typeof window === 'object'
/* eslint-disable no-underscore-dangle */
const composeEnhancers =
dev && windowExist && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: compose
/* eslint-enable */
export function configureStore (initialState = {}) {
/* eslint-disable no-param-reassign */
if (!initialState.toJS) initialState = Immutable(initialState)
const store = createStore(
rootReducer(),
initialState,
composeEnhancers(applyMiddleware(sagaMiddleware))
)
store.sagaTask = sagaMiddleware.run(rootSaga)
return store
}
export function withReduxSaga (BaseComponent) {
return withRedux(configureStore)(nextReduxSaga(BaseComponent))
}