Redux-saga根传奇中的多重传奇

问题描述 投票:0回答:1

这是我的代码:

login.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()]);
}

我的应用仅监听第一个调用的操作,例如LOGOUT_REQUEST,但之后不监听其他操作,即使调用的操作也是如此

yield put()

所以我想我的设置是错误的,知道吗?

reactjs redux redux-saga
1个回答
0
投票

您是否应该尝试使用redux-saga文档中的this example之类的东西?

export default function* loginSaga() {
  while (true) {
    yield take(ELoginActionTypes.AUTHENTICATE_REQUEST);
    yield* authenticate();
    yield take(ELoginActionTypes.LOGOUT_REQUEST),
    yield* logout();
  ];
}
© www.soinside.com 2019 - 2024. All rights reserved.