【问题标题】:How do you further check the action type after ofType?在ofType之后如何进一步检查动作类型?
【发布时间】:2020-10-18 16:26:33
【问题描述】:

我有一个听两种动作类型的史诗,只需将它们称为 setSomething 和 setSomethingFast。对于这些动作,我想使用具有特定值的 debounceTime。问题是我如何知道它当前是哪种动作类型,以便我可以相应地设置去抖动量? ofType 操作符在这里返回一个 Observable,所以我不能在那里使用它。

export const postSomethingEpic = (
  action$: ActionsObservable<PayloadAction<Something[]>>,
  state$: StateObservable<RootState>
): Observable<any> =>
  action$.pipe(
    ofType(setSomething.type, setSomethingFast.type),
    debounceTime(**action$.ofType(##setSomethingFast##)** ? 0 : 2500), <-- How can I tell which action here is which?
    ...
    ...

【问题讨论】:

    标签: react-redux redux-observable


    【解决方案1】:

    我设法想出了一个解决方法。所以我创建了两个史诗,postSomethingEpic 与 debounceTime 和 postSomethingFastEpic 没有去抖动。正常的史诗将发出 setSomethingFast 动作,并传递有效负载。仍然有兴趣知道是否有更短的方法可以做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 2019-11-20
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      相关资源
      最近更新 更多