Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

reactjs - Sequence execution in epic

I need to modify an epic in order to call additional action after finishing deletion, the epic looks like:

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)))),
      ),
    ),
  );

I need to call following action when deletion went successfully, how to do it? Below is import of my action:

import { fetchCategoryComponentList } from '../../store';
question from:https://stackoverflow.com/questions/65942805/sequence-execution-in-epic

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is no requirement that you need to have a one-to-one in/out ratio. You can emit multiple actions using mergeMap (aka flatMap) if you need to. You can do following -

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

Read this answer for more info: https://stackoverflow.com/a/40895613/11167389


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...