Javascript 同构Redux应用程序未注册Redux Thunk?
我好像有一只奇怪的虫子。我目前正在使用Redux同构,并且还包括Javascript 同构Redux应用程序未注册Redux Thunk?,javascript,reactjs,redux,redux-framework,redux-thunk,Javascript,Reactjs,Redux,Redux Framework,Redux Thunk,我好像有一只奇怪的虫子。我目前正在使用Redux同构,并且还包括Redux thunk作为异步操作的中间件。以下是我的商店配置的外观: // Transforms state date from Immutable to JS const transformToJs = (state) => { const transformedState = {}; for (const key in state) { if (state.hasOwnProperty(key)) tr
Redux thunk
作为异步操作的中间件。以下是我的商店配置的外观:
// Transforms state date from Immutable to JS
const transformToJs = (state) => {
const transformedState = {};
for (const key in state) {
if (state.hasOwnProperty(key)) transformedState[key] = state[key].toJS();
}
return transformedState;
};
// Here we create the final store,
// If we're in production, we want to leave out development middleware/tools
let finalCreateStore;
if (process.env.NODE_ENV === 'production') {
finalCreateStore = applyMiddleware(thunkMiddleware)(createStore);
} else {
finalCreateStore = applyMiddleware(
createLogger({transformer: transformToJs}),
thunkMiddleware
)(createStore);
}
// Exports the function that creates a store
export default function configureStore(initialState) {
const store = finalCreateStore(reducers, initialState);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('.././reducers/index', () => {
const nextRootReducer = require('.././reducers/index');
store.replaceReducer(nextRootReducer);
});
}
return store;
}
奇怪的是,我不认为这个文件有什么问题,因为我的createLogger
应用得很好。它会注销我的所有动作和状态,但当我返回一个函数而不是动作创建者中的一个对象时,执行就会丢失。我试着加入debugger
语句,这些语句从未命中中间件并对其重新排序,但似乎也没有帮助
createUser(data) {
// This `debugger` will hit
debugger;
return (dispatch) => {
// This `debugger` will NOT hit, and any code within the function will not execute
debugger;
setTimeout(() => {
dispatch(
AppActionsCreator.createFlashMessage('yellow', 'Works!')
);
}, 1000);
};
},
以前有人经历过类似的事情吗?DOH!我并没有派遣行动。我只是打电话给动作创造者。我得习惯Redux 我如何认为我在调用一个动作:
AppActionCreators.createFlashMessage(“一些消息”)代码>
如何在Redux中实际调用操作:
this.context.dispatch(AppActionCreators.createFlashMessage('some message')代码>
其中,dispatch
是Redux商店提供的一种方法,可以通过React的childContextTypes
传递给应用程序的每个子组件,也许可以用代码说明您的答案。你的解决方案是什么,甚至可能解释出哪里出了问题,这样其他人就可以避免这个错误。