如果您想检查它,这是我的确切代码:
export default function configureStore() {
engine = createEngine('appstate');
engine = filter(engine, null, ['appStateLoaded', 'appReady', 'tourReady', 'tourPage', 'tooltipStep', 'connected']);
const cacheState = storage.createMiddleware(engine); //OLD PARAMETER: , [LOAD, 'SET_TOUR_READY', 'SET_TOUR_PAGE'] ... replaced by reducer key filtering above instead
enhancer = compose(
applyMiddleware(thunk, cacheState),
devTools({
name: Platform.OS,
hostname: '10.0.1.201',
port: 5678,
filters: {blacklist: ['REDUX_STORAGE_SAVE']}
})
);
//reset reducer state on LOGOUT
const appReducer = combineReducers(reducers);
const rootReducer = (state, action) => {
if (action.type === LOGOUT) {
state = undefined;
}
return appReducer(state, action);
}
reducer = storage.reducer(rootReducer);
store = createStore(reducer, enhancer);
//retreive previously cached state and inject into Redux store!
const load = storage.createLoader(engine);
load(store)
.then((newState) => console.log('Loaded state:', newState))
.catch(() => console.log('Failed to load previous state'));
if(module.hot) {
module.hot.accept(() => {
let nextRootReducer = storage.reducer(rootReducer);
store.replaceReducer(nextRootReducer);
load(store)
.then((newState) => console.log('Loaded state:', newState))
});
}
return store;
}
它应该为您提供一个可靠的示例,说明如何将各种中间件与module.hot.accept
. ...就“循环引用”而言——唯一要做的就是检查你的减速器并确保它们不会相互导入。我想我实际上已经看到了这个确切的问题——ES6 模块可以正确地解决循环初始构建,但也许 HMR 构建过程不能。就这样。所以你最终认为你的代码可以工作,但它基本上不支持 HMR。我会设置一个快速测试应用程序并实施他们的hot.module.accept
代码并验证它是否适合您。也许你必须调整一件事——但由于你的代码太少,很容易找到——然后在你自己的代码中进行同样的修复。如果这还没有解决问题,那么请暂时尽量减少您在应用程序中使用 redux 所做的事情,直到您找出导致问题的原因。..希望我有更多的建议给你。