redux-observable如何用管道调度多个动作?

时间:2018-02-21 06:13:40

标签: redux observable redux-observable

我意识到了

const pingEpic = action$ =>
  action$.ofType('PING')
    .delay(1000) // Asynchronously wait 1000ms then continue
    .mapTo({ type: 'PONG' });

平均

dispatch({ type: 'PING' });
dispatch({ type: 'PONG' });

Howeber,我没有意识到如何用管道发送两个动作。

我的代码在

之下
const signUpEpic = (action$: Observable<Action>) => action$.pipe(
  ofType(actions.GET_DEVICE_TOKEN),
  ofType(actions.SIGN_UP),
  exhaustMap(({ payload }) => request({
    url: 'users',
    method: 'post',
    data: {
      user: {
        email: payload.email,
        password: payload.password,
        device_token: payload.device_token,
        sign_up_with: 'email_and_password',
      },
    },
  }).pipe(
    map(data => camelcaseKeysDeep(data)),
    map(({ user, authToken }) => currentUserActions.successLogin({ user, authToken })),
    catchError((errorMessage: string) => Observable.of(actions.failLogin({ errorMessage }))),
  )),
);

你有什么想法吗?

我也试过下面的代码。

ofType(actions.GET_DEVICE_TOKEN),
mapTo(actions.SIGN_UP),

感谢

1 个答案:

答案 0 :(得分:0)

您可以使用mergeMap调度多个操作

texts = [node.text.strip().split('\n')[0] for node in soup.find_all(class_="no-wrap text-right circulating-supply")]