【发布时间】:2018-10-10 15:09:34
【问题描述】:
我在一个项目中使用 react with redux 和 redux-thunk(我们使用中间件)。
这是一个超过 100k 行代码的项目,所以我不知道幕后的一切。
我有一个简单的问题,当我将数据提取到服务器(在 .Net 中)时,我有一个加载程序让用户知道服务器正在工作。
我的 .js 文件包含获取数据的操作:
// Query Count management
export function segmentCount(queryIndex) {
return function(dispatch) {
dispatch({ type: ActionTypes.COUNT + '_PENDING', payload: { queryIndex: queryIndex } });
axios.post(urls.SegmentCount, [queryIndex])
.then((response) => {
dispatch({ type: ActionTypes.COUNT + '_FULFILLED', payload: { queryIndex: queryIndex, response: response } });
})
.catch((err) => {
dispatch({ type: ActionTypes.COUNT + '_REJECTED', payload: { queryIndex: queryIndex, response: err } });
});
}
}
export function actionCount(queryIndex) {
return function(dispatch) {
dispatch({ type: ActionTypes.COUNT + '_PENDING', payload: { queryIndex: queryIndex } });
axios.post(urls.ActionCount, [queryIndex])
.then((response) => {
dispatch({ type: ActionTypes.COUNT + '_FULFILLED', payload: { queryIndex: queryIndex, response: response } });
})
.catch((err) => {
dispatch({ type: ActionTypes.COUNT + '_REJECTED', payload: { queryIndex: queryIndex, response: err } });
});
}
}
还有我调用函数的 jsx:
segmentCount() {
this.props.dispatch(segmentCount(this.props.queryId));
}
actionCount() {
this.props.dispatch(actionCount(this.props.actionId));
}
加载器通常在我们有 ActionTypes_PENDING 时出现。
一切正常,我添加了函数actionCount,它可以工作,但是我没有加载器,而使用segmentCount时,我有它。
我完全不知道去哪里解决这个问题。如果有人知道在哪里看这个,我会很高兴的!如果您需要具体信息,请告诉我。
提前感谢社区!
【问题讨论】:
标签: reactjs redux redux-thunk dispatch