在 Redux Observable 中完成所有操作后调度操作

Dispatch an action after all actions are finished in Redux Observable

你能给我一个建议如何等待多个 Redux 调度然后做一些动作吗?常见的场景是应用程序的初始化(例如等待 FETCH_SOMETHING_SUCCESS 和 FETCH_ELSE_SUCCESS 然后调度 APP_INIT_SUCCESS)。

类似...

  export const appInitSuccessEpic = (action$) =>
  action$.pipe(
    whenAllDispatched('FETCH_ONE', 'FETCH_SECOND'),
    map(() => { type: 'APP_INIT_SUCCESS' })
  )

谢谢:)

您可以使用 zip 运算符。

After all observables emit, emit values as an array

import { ofType } from 'redux-observable';

export const appInitSuccessEpic = (action$) => 
 zip(
    action$.pipe(ofType("FETCH_THIS_SUCCESS")),
    action$.pipe(ofType("FETCH_ELSE_SUCCESS"))
  )
 .pipe(mapTo({ type: 'APP_INIT_SUCCESS' }))