如何使用withLatestFrom运算符在Effects中获取存储状态

问题描述 投票:0回答:1

我正在尝试此

payloadToBeSaved$ = createEffect(() =>  this.actions$
.ofType(SOME_ACTION)
.withLatestFrom(this.store$)
.map(([action: Action, storeState: AppState]) => {
   // Do something ...
});

但是this.actions $是可观察的,我必须使用this.actions $ .pipe()....当我尝试使用pipe()时,所有行都带有错误的红色。不知道如何解决。

ngrx ngrx-store
1个回答
0
投票
@Effect()
shipOrder = this.actions.pipe(
  ofType<ShipOrder>(ActionTypes.ShipOrder),
  map(action => action.payload),
  concatMap(action =>
    of(action).pipe(
      withLatestFrom(store.pipe(select(getUserName)))
    )
  ),
  map([payload, username] => {
    ...
  })
)

参考:Start using ngrx/effects for this

© www.soinside.com 2019 - 2024. All rights reserved.