Search code examples
angularngrx-storengrx-entity

My action is not calling associated reducer and effect


my action -

export class RefreshToken implements Action {
 readonly type = GeneralActionTypes.refreshToken;

 constructor(public token: string) {
  console.log('%c action called ', 'background:#00e;color:#000', token);
 }
}

associated effect -

@Effect({dispatch: false})
refreshToken$: Observable<Action> = this.actions$.pipe(
 ofType<RefreshToken>(GeneralActionTypes.refreshToken),
 map(a => {
  console.log('%c effect is called ', 'background:#00e;color:#000', a)
  return a;
 })
);

and reducer -

case GeneralActionTypes.refreshToken:
  console.log('inside refresh token ', action);
  return state;

when i am calling the action -

new RefreshToken('i am called qwerty ');

the action runs and console written in it get printed but the associated effect and reducer doesn't run.

Note: i am using ngrx store entities, with angular 8.


Solution

  • You need call the dispatch method of the store. Before this, inject an instance of the store, and call the dispatch method with a parameter which is an action. Ex: this.store.dispatch(new RefreshToken('parameter'); And also check your imports (StoreModule, EffectsModule).