通过另一个 switchMap 和过滤器传递 switchMap 效果中的动作值?

Pass the action value in effects for switchMap via both another switchMap and filter?

有密码

  @Effect()
  myEffect$ = this.actions$.pipe(
    ofType(MyActions.doSomething),
    tap(() => this.store.dispatch(MyActions.doSomething2())),
    switchMap(action => {
      

有效。 我需要在点击之前注入一个过滤器。怎么做才能让switchMap的action值不丢失?

我正在尝试这样做

  @Effect()
  myEffect$ = this.actions$.pipe(
    ofType(MyActions.doSomething),
    switchMap(() => this.store.pipe(select(mySelectors.getAmount), take(1))),
    filter(amount => amount <= 0),
    tap(() => this.store.dispatch(MyActions.doSomething2())),
    switchMap(action => {
    ....

然而它说 property action.xxxx doesn't exist on type number 这很清楚为什么。如何不丢失MyActions.doSomething返回的action值?

如果过滤器仅适用于那些值以实现更好的封装,我会直接在金额存储的运算符链中移动过滤器。然后您不必导出 switchMap 之外的金额,只需将它们重新映射到操作:

  @Effect()
  myEffect$ = this.actions$.pipe(
    ofType(MyActions.doSomething),
    switchMap(action => this.store.pipe(
      select(mySelectors.getAmount),
      take(1),
      filter(amount => amount <= 0), // filter amounts here
      map(_ => action) // remap to actions
    ))),
    tap(() => this.store.dispatch(MyActions.doSomething2())),
    switchMap(action => {
      // ...
    })