I have several Effect listeners that need to run until the user has logged out. As such, I'm trying to implement OnRunEffects.
A segment of my user.actions.ts is:
export const LOAD_USER = '[Users] Load User';
export class LoadUser implements Action {
readonly type = LOAD_USER;
}
export type UserActions = LoadUser;
I'm trying to implement OnRunEffects as:
ngrxOnRunEffects(resolvedEffects: Observable<EffectNotification>) {
return this.actions
.ofType(UsersActions.LOAD_USER)
.exhaustMap(() => resolvedEffects.takeUntil(AuthActions.LOGOUT_SUCCESS)
}
However, takeUntil is complaining that it needs as Observable. So I tried:
ngrxOnRunEffects(resolvedEffects: Observable<EffectNotification>) {
return this.actions
.ofType(UsersActions.LOAD_USER)
.exhaustMap(() => resolvedEffects.takeUntil(
Observable.of(new AuthActions.LogoutSuccess())
)
}
That in turn, causes the effect to not fire. From reading the code, it looks like it states:
- When you see these actions
- run the effects
- until you see this other action.
What am I doing wrong?
Correct me if I'm wrong, but you might not want to
run until the user has logged out
, you might just want to run those effects if the user is still logged in. If yes, then instead of thinking totakeUntil
: