1

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 enter image description here

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?

critrange
  • 5,652
  • 2
  • 16
  • 47
The.Wolfgang.Grimmer
  • 1,172
  • 2
  • 9
  • 32
  • Since BookmarksModule is lazy loaded module so it’s effect is not loaded yet, as a result the effect did not get called. The effect will be called when the BookmarksModule is loaded. You can try it. – user2216584 Sep 21 '20 at 05:34
  • @user2216584 , how should i do it in this case, if need to listen to the action from the eager loaded module? – The.Wolfgang.Grimmer Sep 21 '20 at 06:41
  • Is BooknarksModule is angular feature module or ngrx feature Module? If it is a ngrx feature module then you need to eager load it. If it’s an angular feature module then you cannot do whatever you are trying to achieve, you will have to change the design a bit. – user2216584 Sep 21 '20 at 13:43
  • yup, the BookmarksModule is a feature module. Basically what i want is after login, i want to dispatch a certain action. – The.Wolfgang.Grimmer Sep 22 '20 at 01:46

0 Answers0