How to handle several types of actions in one epic? Any cons of the same?

Quite new for reduction observables, rxjs and observables. I wanted to know how I can handle another action, say "ActionTwo" in the same epic

const Epic1 = (action$,store) => {
return action$.ofType('ActionOne')
 .mergeMap((action) => {
      return ajax({'method': 'GET', 'url': 'someUrl')
         .map(response => resultActoin(action.userId, response.response));


       }
  );
 }

Sort of

const Epic1 = (action$){
   if('ActionOne') make a API call.
   if('ActionTwo') make some other API call.
   else do nothing.

}
+6
source share
1 answer

Is this the same API call? If yes, ofType()accepts several types. You can just do it action$.ofType('ActionOne', 'ActionTwo').

API/URL, . "" combineEpics .: https://redux-observable.js.org/docs/basics/SettingUpTheMiddleware.html

+12

Source: https://habr.com/ru/post/1015789/


All Articles