【问题标题】:Sequence execution in epic史诗中的序列执行
【发布时间】:2021-05-02 16:25:13
【问题描述】:

我需要修改史诗以便在完成删除后调用附加操作,史诗 看起来像:

const deleteComponentEpic: Epic<
  AppActions,
  AppActions,
  AppStore,
  ComponentDetailsEpicsDependencies
> = (action$, _, { components }) =>
  action$.pipe(
    filterAction(deleteComponentAction.request),
    exhaustMap(action =>
      components.deleteComponent(action.payload.id).pipe(
        map(() => deleteComponentAction.success()),
        catchError((error: Error) => of(deleteComponentAction.failure(errorHandler(error)))),
      ),
    ),
  );

删除成功后需要调用下面的动作,怎么做?以下是我的行动的导入:

import { fetchCategoryComponentList } from '../../store';

【问题讨论】:

    标签: reactjs typescript rxjs


    【解决方案1】:

    没有强制要求您必须具有一对一的输入/输出比例。如果需要,您可以使用 mergeMap(又名 flatMap)发出多个操作。 您可以执行以下操作 -

    components.deleteComponent(action.payload.id).pipe(
            mergeMap(() => of(deleteComponentAction.success(), fetchCategoryComponentList())),
            catchError((error: Error) => of(deleteComponentAction.failure(errorHandler(error)))),
          ),
    

    阅读此答案以获取更多信息:https://stackoverflow.com/a/40895613/11167389

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多