0

i am using tap operator in multiple places in the effect. but some how i am not seeing the console logs in the browser.

here is my effect.

  getAccountDetails$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(getAccountDetails),
      tap((action) => console.log(`Received ${action.type}`)),
      withLatestFrom(this.store.select(selectAccounts)),
      tap((accs) => console.log(`Received ${accs}`, accs)),
      mergeMap((accounts) => {
        console.log('acconts from accounts details : ', accounts);
        return this.accountService.getAccounts$().pipe(
          map((accounts) => {
            console.log(accounts);
            return getAccountsSuccess({ payload: accounts });
          }),
          catchError((error) => {
            return of(getAccountsError({ errorMessage: error.message }));
          })
        );
      })
    );
  });

i am dispatching my action from the component ngOninit.

ngOnInit(): void {
    this.store.dispatch(getAccounts());
    this.store.dispatch(getAccountDetails());
  }

when i verify the actions being called in the browser redux devtools , i can see the correct flow. enter image description here

Q: wondering why my console.log is not printing, is there any better way to debug the effects ?

sravan ganji
  • 4,774
  • 3
  • 25
  • 37
  • 1
    Breakpoints are pretty much always a better choice than console logs :) if your effects aren't getting called, it's most likely because you haven't registered them with EffectsModule… – Will Alexander Mar 07 '22 at 14:03

1 Answers1

0

You probably need to register the effect with EffectsModule.forRoot([YourEffectClass]) or EffectsModule.forFeature([YourEffectClass])

https://ngrx.io/guide/effects#registering-root-effects

timdeschryver
  • 14,415
  • 1
  • 19
  • 32