redux - 如何在一部史诗中处理多种 Action 类型?这样做有什么缺点吗?

标签 redux observable rxjs5 redux-observable

redux-observables、rxjs 和 observables 非常新。想知道我如何处理另一个 Action ,在同一个史诗中说“ActionTwo”

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


       }
  );
 }

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

}

最佳答案

它是相同的 API 调用吗?如果是这样,ofType()接受不止一种类型。你可以做 action$.ofType('ActionOne', 'ActionTwo') .

如果您想向另一个 API/URL 发出请求,我建议您制作另一个史诗。您可以使用 combineEpics“合并”所有史诗见:https://redux-observable.js.org/docs/basics/SettingUpTheMiddleware.html

关于redux - 如何在一部史诗中处理多种 Action 类型?这样做有什么缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42832974/

相关文章:

angular - 我如何从 RXJS 5.5.6 模拟 fromEvent 函数?

angular - RxJS: takeUntil() Angular 组件的 ngOnDestroy()

javascript - RxJS 如何忽略 catch 的错误并继续前进

javascript - SubmissionError 是否适用于 FieldArray 字段?

javascript - 使用 RxJS switchMap 仅取消订阅具有相同请求 URL/操作负载的流(redux-observable 史诗)

java - mockito - 伪造 addObserver

javascript - Angular 6 : How to prevent 2 subscribed variables in one Observable from cascading each other

javascript - React Server Side Rendering App - 如何更新元数据

reactjs - redux 标准化状态 : byId and allIds pattern

angular - 在服务中拥有持久数据的正确方法