我正在研究纯粹是redux-saga的应用程序,但是随着应用程序的增长,文件的数量也在增长。为了解决此问题,我正在尝试将redux-starter-kit设置为当前应用程序。
这是我的商店配置文件index.js
import { configureStore, getDefaultMiddleware } from 'redux-starter-kit'
import rootReducer from '../reducers'
export const store = configureStore({
reducer: rootReducer,
middleware: [...getDefaultMiddleware()]
})
仅用于redux-saga的旧设置,而没有redux-starter-kit
// import createSagaMiddleware from 'redux-saga'
// import { initSagas } from '../initSagas'
// import rootReducer from '../reducers'
// import { loadState, saveState } from './browserStorage'
// function configureStore () {
// const sagaMiddleware = createSagaMiddleware()
// const persistedState = loadState()
// const createdStore = createStore(
// rootReducer,
// persistedState,
// applyMiddleware(sagaMiddleware)
// )
// initSagas(sagaMiddleware)
// return createdStore
// }
// export const store = configureStore()
// store.subscribe(() => {
// saveState(store.getState())
// })
问题:
当我设置redux-starter-kit时,旧的sagas无法正常工作。
长话短说:
如何在不干扰当前saga文件的情况下使用redux-starter-kit设置现有的redux-saga应用程序?
谢谢。
答案 0 :(得分:1)
redux-starter-kit
默认不包含sagaMiddleware
[1]。您需要将其添加到中间件列表中,然后自行初始化sagas。
对于您而言,我认为这应该可行:
import createSagaMiddleware from 'redux-saga'
import { configureStore, getDefaultMiddleware } from 'redux-starter-kit'
import rootReducer from '../reducers'
import { initSagas } from '../initSagas'
const sagaMiddleware = createSagaMiddleware();
export const store = configureStore({
reducer: rootReducer,
middleware: [...getDefaultMiddleware(), sagaMiddleware]
})
initSagas(sagaMiddleware);
[1] https://redux-starter-kit.js.org/api/getdefaultmiddleware