Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Redux saga调用多个函数/操作_Javascript_Reactjs_Redux_Redux Saga - Fatal编程技术网

Javascript Redux saga调用多个函数/操作

Javascript Redux saga调用多个函数/操作,javascript,reactjs,redux,redux-saga,Javascript,Reactjs,Redux,Redux Saga,在我的故事中,我想用不同的动作调用两个不同的函数: 导出默认函数*(){ 收益率(actionTypes.ADD_ACCOUNT,addAccountSaga); 收益率(actionTypes.GET_WALLET、getBalanceSaga); } 我读过一些文章,并尝试将它们按如下方式排列: 产量[( takeLatest(actionTypes.ADD_ACCOUNT,addAccountSaga), takeLatest(actionTypes.GET_WALLET,getBala

在我的故事中,我想用不同的动作调用两个不同的函数:

导出默认函数*(){
收益率(actionTypes.ADD_ACCOUNT,addAccountSaga);
收益率(actionTypes.GET_WALLET、getBalanceSaga);
}
我读过一些文章,并尝试将它们按如下方式排列:

产量[(
takeLatest(actionTypes.ADD_ACCOUNT,addAccountSaga),
takeLatest(actionTypes.GET_WALLET,getBalanceSaga)
)];
但遗憾的是,它不起作用,我也尝试了这种方法:

yield*takeLatest(actionTypes.ADD\u ACCOUNT,addAccountSaga);
收益率*takeLatest(actionTypes.GET_WALLET,getBalanceSaga);
我还将console.log放入其中一个函数中,以确定其是否工作,但console.log未工作,这意味着未调用该函数

但这也不起作用。你能帮我解决这个问题吗?

你可以用

创建一个效果描述,指示中间件并行运行多个效果,并等待所有效果完成


对于一个文件中的多个文件,您必须执行以下操作:

export function* getShirtPlans() {
  try {
    const response = yield call(API.apiGetShirtPlans);
    yield put(ACTIONS.setShirtPlans(response.data.data.intervals));
  } catch (err) {
    console.log(err);
  }
}

export function* getShirtStyles() {
  try {
    const response = yield call(API.apiGetShirtStyles);
    console.log(response.data.data);
    yield put(ACTIONS.setShirtStyles(response.data.data));
  } catch (err) {
    console.log(err);
  }
}

export function* watchOngetShirtPlans() {
  yield takeLatest(TYPES.GET_SHIRTS_PLANS, getShirtPlans);
}

export function* watchOngetShirtStyles() {
  yield takeLatest(TYPES.GET_SHIRTS_STYLES, getShirtStyles);
}
在主要的saga索引文件中,导入如下内容:

import { fork, all } from "redux-saga/effects";
import { watchOngetShirtPlans, watchOngetShirtStyles } from "../sagas/ShirtsSaga";

export function* watchSagas() {
  yield all([
    fork(watchOngetShirtPlans),
    fork(watchOngetShirtStyles)
  ]);
}
import { fork, all } from "redux-saga/effects";
import { watchOngetShirtPlans, watchOngetShirtStyles } from "../sagas/ShirtsSaga";

export function* watchSagas() {
  yield all([
    fork(watchOngetShirtPlans),
    fork(watchOngetShirtStyles)
  ]);
}