相关疑难解决方法(0)

如何在效果中访问状态树?(@ ngrx/effects 2.x)

我正在将@ ngrx/effects从1.x 更新为2.x.

在1.x中,我可以访问状态树:

  constructor(private updates$: StateUpdates<AppState>) {}

  @Effect() bar$ = this.updates$
    .whenAction(Actions.FOO)
    .map(obj => obj.state.user.isCool)
    .distinctUntilChanged()
    .filter(x => x)
    .map(() => ({ type: Actions.BAR }));
Run Code Online (Sandbox Code Playgroud)

现在在2.x中,它只给了我动作.还有办法访问状态树吗?或者我应该避免这样使用,因为这不是一个好习惯吗?

  constructor(private actions$: Actions) {}

  @Effect() bar$ = this.actions$
    .ofType(ActionTypes.FOO)
    .map((obj: any) => {
      console.log(obj);              // here is action only
      return obj.state.user.isCool   // so it is wrong here
    })
    .distinctUntilChanged()
    .filter(x => x)
    .map(() => ({ type: ActionTypes.BAR }));
Run Code Online (Sandbox Code Playgroud)

typescript ngrx angular

22
推荐指数
2
解决办法
5680
查看次数

标签 统计

angular ×1

ngrx ×1

typescript ×1