我正在将@ 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)