简体   繁体   English

Redux-saga root saga 中的多个 saga

[英]Redux-saga multiple saga in root saga

Here is my code:这是我的代码:

login.saga.ts登录.saga.ts

export function* authenticate(action: AuthenticateRequestAction) {
  ...
}

export function* logout(action: LogoutRequestAction) {
  try {
    yield LoginService.logout(action.data);
    yield put(AppActions.resetUser());
    yield put(loginActions.setAuthenticationSuccessRequest(false));
  } catch (err) {
    Notification({
      type: 'error',
      message: err.message,
      description: i18n.t('login.logoutFailed'),
    });
  }
}

export default function* loginSaga() {
  yield [
    takeLatest(ELoginActionTypes.AUTHENTICATE_REQUEST, authenticate),
    takeLatest(ELoginActionTypes.LOGOUT_REQUEST, logout),
  ];
}

rootSaga.ts根目录

export default function* rootSaga() {
  yield all([appSaga(), loginSaga()]);
}

My app is just listening to the first action called, for example LOGOUT_REQUEST but won't listen other actions after that one, even the actions called with我的应用程序只是在听第一个调用的动作,例如LOGOUT_REQUEST但不会听那个之后的其他动作,即使是用

yield put()

So I guess my setup is wrong, any idea ?所以我想我的设置是错误的,知道吗?

Should you not try something like this example from the redux-saga docs?你不应该尝试像 redux-saga 文档中的这个例子吗?

export default function* loginSaga() {
  while (true) {
    const authAction = yield take(ELoginActionTypes.AUTHENTICATE_REQUEST);
    yield* authenticate(authAction);
    const logoutAction = yield take(ELoginActionTypes.LOGOUT_REQUEST),
    yield* logout(logoutAction);
  };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM