How to get access of the state tree in effects? (@ngrx/effects 2.x)

前端 未结 2 774

I am updating @ngrx/effects from 1.x to 2.x

In 1.x I have access of state tree in effect:

  constructor(private updates$: StateUpdates

        
2条回答
  •  时光取名叫无心
    2020-12-15 06:03

    Another way is using .withLatestFrom(this.store). So the complete code is:

      constructor(
        private actions$: Actions,
        private store: Store
      ) {}
    
     @Effect() bar$ = this.actions$
        .ofType(ActionTypes.FOO)
        .withLatestFrom(this.store, (action, state) => state.user.isCool)
        .distinctUntilChanged()
        .filter(x => x)
        .map(() => ({ type: ActionTypes.BAR }));
    

提交回复
热议问题