ngrx/effects 对来自状态的值使用延迟运算符

ngrx/effects use delay operator with value from state

在我的应用程序中,我跟踪会话时间

  @Effect()
  session$: Observable<Action> = this.actions$
    .ofType(authAction.RESET_SESSION)
    .switchMap(_ => Observable.of({ type: authAction.LOGOUT })
                .delay(600000);

*每次调用 RESET_SESSION 操作时,注销操作都会等待 10 分钟。

在我的应用程序中,我从服务器获取会话时间并在登录后存储状态。我怎么可以延迟使用这个存储值?! (因为在 ngrx 存储中 return 可观察而不是状态对象)

像这样:

 @Effect()
  session$: Observable<Action> = this.actions$
    .ofType(authAction.RESET_SESSION)
    .switchMap(_ => Observable.of({ type: authAction.LOGOUT })
                .delay(this.store.pluck('auth','sessionTime'));

您需要通过构造函数将商店注入 Effects。类似于:

@Injectable()
export FooEffects {
   @Effect()
    session$: Observable<Action> = this.actions$
    .ofType(authAction.RESET_SESSION)
    .mergeMap(_ => this.store.select(getSessionTime)) //getSessionTime would be a selector
    .switchMap(delay => Observable.of({ type: authAction.LOGOUT }).delay(delay));

   ctor(
   private actions$: Actions,
   private store: Store<rootState>){}
}