NgRx:如何从效果中 console.log a store.select?

NgRx: How to console.log a store.select from inside an effect?

我正在学习 NgRx 并尝试 console.log 从效果中的商店中选择的一些值。我对 RxJs 了解不多。当我尝试时,它显示的是这样的东西,而不是数字:

代码如下:

resetSample$= createEffect(() => this.actions$.pipe(
    ofType(DecisorActions.ResetSampleAction),
    map(() => { 
        this.file.readlineGuard(); // throw EOF error

        // I would like to console.log() those number values:
        console.log(this.store.select(Selectors.getA)));
        console.log(this.store.select(Selectors.getB)));
        console.log(this.store.select(Selectors.getC)));

        console.log('RESET SAMPLE EFFECT');

        return DecisorActions.BuyAction({payload: 0});
    }),
    catchError( err => { console.log('EOF detected'); return of(DecisorActions.EndOfFileError({payload:0})); })
));

如果我遗漏了一些重要的概念,我也非常感谢有关阅读/查找内​​容的建议。

一个很好的资源是 NgRx Encorprating State,它使用 concatLatestFrom。或者,您可以使用 RxJs 运算符 withLatestFrom。从那个 NgRx link,它指出:

When state is needed, the RxJS withLatestFrom or the @ngrx/effects concatLatestFrom operators can be used to provide it.

基本上你会有一些类似的东西:

resetSample$= createEffect(() => this.actions$.pipe(
    ofType(DecisorActions.ResetSampleAction),
    withLatestFrom(
      this.store.select(Selectors.getA),
      this.store.select(Selectors.getB),
      this.store.select(Selectors.getC)
    ),
    map(([action, a, b, c]) => { 
        this.file.readlineGuard(); // throw EOF error

        // Log values here:
        console.log(a);
        console.log(b);
        console.log(c);

        console.log('RESET SAMPLE EFFECT');

        return DecisorActions.BuyAction({payload: 0});
    }),
    catchError( err => { console.log('EOF detected'); return of(DecisorActions.EndOfFileError({payload:0})); })
));

注意:如果使用 RxJS 版本 6,withLatestFrom 中只允许有 5 个参数。请参阅 this Github 问题。

从版本 7 开始,代码已更新为允许任意数量的参数。请参阅运算符 here.

的代码