NGRX Multiple store features communication

Viewed 857

I have multiple feature stores registered with

StoreModule.forFeature('feature1', reducers)
StoreModule.forFeature('feature2', reducers)
StoreModule.forFeature('feature3', reducers)

In some cases, one store is affecting other store(s).

For example dispatching an action 'edit' in 'feature1' should trigger a server call in both feature 2 and feature 1 and should also change the state of feature 3.

Should I create an effect in every feature store to listen the feature 1 action even it's another store? And what about feature 3? how do I change the state of other feature store, let's say after the server request finished in feature 1 effect:

 EditFeature1$: Observable<Action> = createEffect(() =>
    this.action$.pipe(
      ofType(Feature1Action.EditAction),
      mergeMap(action =>
        this.http.get(`url`).pipe(
          map((data) => {
            // how to affect other states from here (of feature 2 or 3)
          }),
          catchError((error: Error) => {
            return of(Error(error));
          })
        )
      )
    )
  );

Is it a good practice to change and listen to other feature store actions? or every one of them need to be isolated and only knows it's a own actions and state

0 Answers
Related