我正在尝试分派多个动作,这些动作将触发多个生成器功能。
点击
dispatch({ type: "ACTION_1", data1});
dispatch({ type: "ACTION_2", data2});
传奇.js
function* method1(action){
//...
const response = yield call(api, requestParams);
//...
}
function* method2(action){
//...
const response1 = yield call(api, requestParams1);
//...
//dependent on response1
const response2 = yield call(api, requestParams2);
//...
//dependent on response2
const response3 = yield call(api, requestParams3);
//...
}
function* actionWatcher() {
yield all([
takeLatest("ACTION_1", method1),
takeLatest("ACTION_2", method2),
]);
}
export default function* sagas() {
yield all([actionWatcher()]);
}
OnClick,method1 被调用,我可以看到一个网络调用,并且在 console 上有这个错误Error: Generator is already running
。
我试图takeEvery
在好actionWatcher()
方法,同样的错误。
我如何实现这一目标?