ngrx效果:调度空动作

Bar*_*uzi 4 rxjs ngrx angular

如何获得我的ngrx / store效果来调度空动作?我正在运行Angular 6 / rxjs 6:

  @Effect()
  testEffect$ = this.actions$.ofType(FIRST_ACTION).pipe(
    map((x) => {
       if (x === y) {
          return new SECOND_ACTION;
       } else {
          fire.some.effect;
          return EMPTY;
       }
    })
  );
Run Code Online (Sandbox Code Playgroud)

目前,我遇到两个错误:Effect "testEffect$" dispatched an invalid action: [object Object]其次是TypeError: Actions must have a type property

我找到了这个答案,但是它似乎不适用于ng / rxjs6。到目前为止,我已经尝试了以下方法(无作用):

EMPTYObservable.empty()Observable.of()Observable.of([]){ type: 'EMPTY_ACTION' }

任何帮助,将不胜感激!我知道我可以使用{ dispatch: false },但是实际效果大约有5个结果,而其中只有一个不使用操作,因此我宁愿最后一个结果也有所回报。

小智 11

这是一个可能的解决方案:

@Effect()
  testEffect$ = this.actions$.ofType(FIRST_ACTION).pipe(
    tap((x) => { // do some side effect here
        if (x !== y ) {
            fire.some.effect;
        }
    }),
    filter((x) => x === y), // proceed only if condition is true
    map((x) => {
       return new SECOND_ACTION; // then return the needed action
    })
  );
Run Code Online (Sandbox Code Playgroud)