【发布时间】:2017-08-28 19:50:30
【问题描述】:
我在我的 react redux 应用程序中使用 fetch api 以及 redux saga 问题是我在 fetch api 中有同步调用。但不,我的那个电话不是通过传奇触发的。下面是我的第一个电话
import {fetchAggregatedData1,
fetchAggregatedData2
} from '../actions/mixActions';
fetch(types.BASE_URL + types.DATA_URL).then(response => {
var res=response.json();
console.log('response',res)
const maxYear = Math.max.apply(
Math,
res.map(function(data) {
return data.year;
})
);
console.log('trigered in api')
fetchAggregatedData2(maxYear);
fetchAggregatedData1(maxYear);
return res;
以下是我的操作
export function fetchAggregatedData2(year) {
return {
type: types.FETCH_AGGREGATED2,
year
};
}
export function fetchAggregatedData1(year) {
return {
type: types.FETCH_AGGREGATED1,
year
};
}
这是我的传奇 index.js
export default function* startForman() {
yield [
fork(watchAggregate1),
fork(watchAggregate2)
]}
在 watchAggregate1.js 中
export default function* watchAggregate1() {
yield takeLatest(types.FETCH_AGGREGATED1, aggregateSaga1);
}
谁能告诉我为什么同步呼叫没有通过??
【问题讨论】:
标签: reactjs react-redux redux-saga