4
votes

in my application, I tracking for session time

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

*every time that RESET_SESSION action called, the logout action wait 10 minutes.

in my application, i get session time from the server and store on state after login. how I can use this store value in delay?! ( because in ngrx store return observable and not object of state)

something like this:

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

1 Answers

2
votes

You would need to inject the store into the Effects through the constructor. Something like:

@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>){}
}