添加 redux-injectors 会阻止 createStore.apply 函数
Adding redux-injectors brakes the createStore.apply function
我正在尝试在我的项目中添加来自 react-boilerplate 的库 redux-injectors。但是,我在下图中遇到了问题。我的文件 configureStore 如下所示,您也可以在此存储库中找到它:https://github.com/guifeliper/example-redux-injectors
我可以做些什么来让 redux-injectors 工作,当我尝试应用库时总是出现这个错误,似乎我的中间件格式不正确。你有什么线索吗?
function createReducer(injectedReducers = {}) {
const rootReducer = combineReducers({
...injectedReducers,
// other non-injected reducers can go here...
});
return rootReducer
}
export default function testingConfigureStore(preloadedState = {}) {
const sagaMiddleware = createSagaMiddleware();
const runSaga = sagaMiddleware.run;
const injectorMiddleware = createInjectorsEnhancer({
createReducer,
runSaga,
});
const middlewares = [injectorMiddleware]; // loggerMiddleware
const middlewareEnhancer = composeWithDevTools(
applyMiddleware(...middlewares)
);
const enhancers = [middlewareEnhancer];
const composedEnhancers = compose(...enhancers);
const store = createStore(createReducer(), preloadedState, composedEnhancers);
return store;
}
最终解决方案如下:
const staticReducers = {
default: defaultReducer,
}
function createReducer(asyncReducers) {
return combineReducers({
...staticReducers,
...asyncReducers
})
}
export default () => {
let composeEnhancers = compose;
const sagaMiddleware = createSagaMiddleware();
const runSaga = sagaMiddleware.run;
// If Redux Dev Tools and Saga Dev Tools Extensions are installed, enable them
/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && typeof window === 'object') {
/* eslint-disable no-underscore-dangle */
if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__)
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({});
}
const injectEnhancer = createInjectorsEnhancer({
createReducer,
runSaga,
})
const store = createStore(
createReducer(),
composeEnhancers(
applyMiddleware(sagaMiddleware),
injectEnhancer
)
);
store.asyncReducers = {};
return store;
};
检查 CreateStore,我在其中添加了 applyMiddleware 和 InjectEnhancer。我决定在 github 中添加一个完整版本,因为我在网上找不到任何版本。 https://github.com/guifeliper/example-redux-injectors
我正在尝试在我的项目中添加来自 react-boilerplate 的库 redux-injectors。但是,我在下图中遇到了问题。我的文件 configureStore 如下所示,您也可以在此存储库中找到它:https://github.com/guifeliper/example-redux-injectors
我可以做些什么来让 redux-injectors 工作,当我尝试应用库时总是出现这个错误,似乎我的中间件格式不正确。你有什么线索吗?
function createReducer(injectedReducers = {}) {
const rootReducer = combineReducers({
...injectedReducers,
// other non-injected reducers can go here...
});
return rootReducer
}
export default function testingConfigureStore(preloadedState = {}) {
const sagaMiddleware = createSagaMiddleware();
const runSaga = sagaMiddleware.run;
const injectorMiddleware = createInjectorsEnhancer({
createReducer,
runSaga,
});
const middlewares = [injectorMiddleware]; // loggerMiddleware
const middlewareEnhancer = composeWithDevTools(
applyMiddleware(...middlewares)
);
const enhancers = [middlewareEnhancer];
const composedEnhancers = compose(...enhancers);
const store = createStore(createReducer(), preloadedState, composedEnhancers);
return store;
}
最终解决方案如下:
const staticReducers = {
default: defaultReducer,
}
function createReducer(asyncReducers) {
return combineReducers({
...staticReducers,
...asyncReducers
})
}
export default () => {
let composeEnhancers = compose;
const sagaMiddleware = createSagaMiddleware();
const runSaga = sagaMiddleware.run;
// If Redux Dev Tools and Saga Dev Tools Extensions are installed, enable them
/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && typeof window === 'object') {
/* eslint-disable no-underscore-dangle */
if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__)
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({});
}
const injectEnhancer = createInjectorsEnhancer({
createReducer,
runSaga,
})
const store = createStore(
createReducer(),
composeEnhancers(
applyMiddleware(sagaMiddleware),
injectEnhancer
)
);
store.asyncReducers = {};
return store;
};
检查 CreateStore,我在其中添加了 applyMiddleware 和 InjectEnhancer。我决定在 github 中添加一个完整版本,因为我在网上找不到任何版本。 https://github.com/guifeliper/example-redux-injectors