ofType之后如何进一步检查action类型?
How do you further check the action type after ofType?
我有一个侦听两种动作类型的史诗,只需将它们称为 setSomething 和 setSomethingFast。对于这些操作,我想使用具有特定值的 debounceTime。问题是如何判断当前是哪种动作类型,以便我可以相应地设置去抖动量? ofType 运算符 returns 在这里是一个 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?
...
...
我想出了一个解决方法。所以我创建了两个 epics,postSomethingEpic with debounceTime 和 postSomethingFastEpic 没有 debounce。普通史诗将发出 setSomethingFast 操作,并传递有效负载。仍然有兴趣知道是否有更短的方法来做到这一点。
我有一个侦听两种动作类型的史诗,只需将它们称为 setSomething 和 setSomethingFast。对于这些操作,我想使用具有特定值的 debounceTime。问题是如何判断当前是哪种动作类型,以便我可以相应地设置去抖动量? ofType 运算符 returns 在这里是一个 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?
...
...
我想出了一个解决方法。所以我创建了两个 epics,postSomethingEpic with debounceTime 和 postSomethingFastEpic 没有 debounce。普通史诗将发出 setSomethingFast 操作,并传递有效负载。仍然有兴趣知道是否有更短的方法来做到这一点。