rsnext/examples/with-redux-saga/store.js

31 lines
876 B
JavaScript
Raw Normal View History

import { applyMiddleware, createStore } from 'redux'
2017-07-13 20:55:29 +02:00
import createSagaMiddleware from 'redux-saga'
import { createWrapper } from 'next-redux-wrapper'
import rootReducer, { exampleInitialState } from './reducer'
2017-07-13 20:55:29 +02:00
import rootSaga from './saga'
2020-05-18 21:24:37 +02:00
const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
export const makeStore = (context, initialState = exampleInitialState) => {
const sagaMiddleware = createSagaMiddleware()
2017-07-13 20:55:29 +02:00
const store = createStore(
rootReducer,
initialState,
bindMiddleware([sagaMiddleware])
2017-07-13 20:55:29 +02:00
)
store.sagaTask = sagaMiddleware.run(rootSaga)
2017-07-13 20:55:29 +02:00
return store
}
export const wrapper = createWrapper(makeStore, { debug: true })