So here's what i'm trying to do.
Under a lazy-loaded BookmarksModule
feature module, i have an effect that listens to authActions.loginSuccess
w/c is registered in a AuthModule
w/c is not lazy-loaded.
@Injectable({
providedIn: 'root',
})
export class FavoriteEffects {
getFavoriteAfterLogin$ = createEffect(
() => {
return this.actions$.pipe(
ofType(authActions.loginSuccess),
map(() => favoriteActions.getFavorites())
);
}
);
Here's how the authActions.loginSuccess
is dispatched.
loginCallback$ = createEffect(() => {
return this.actions$.pipe(
ofType(authActions.loginCallback),
exhaustMap(() =>
this.authService.currentUser$.pipe(
map(currentUser => authActions.loginSuccess({ currentUser })),
catchError(error =>
of(authActions.loginFailure({ error: error?.error?.message }))
)
)
)
);
});
loginSuccessRedirect$ = createEffect(
() => {
return this.actions$.pipe(
ofType(authActions.loginSuccess),
tap(() => this.router.navigate([this.redirects.login.success]))
);
},
{ dispatch: false }
);
As you can see, when authActions.loginSuccess
is dispatched, it's correctly intercepted by loginSuccessRedirect$
within the same class but this actions is not intercepted within a lazy-loaded module?
This is the screenshot of the actions in ngrx store devtools
It seems like the update-reducers
action for the feature module is dispatched AFTER the loginSuccess
action has already been dispatched.
How do i fix this one?