Sergiu Molnar
Sergiu Molnar

Reputation: 1020

Share data between Angular reducers

I have a situation in my app where I need to share data between reducers.

State:
{
   ...
   itemDetails,
   settings
}

In the itemDetails store, I need to update some data and to be able to do this I need some data from the settings store.

(I’m also using facades.)

Is there a possibility to share data between reducers like redux-thunk in react or something like this?

I also have other two options to do this:

  1. Send that settings data to the facade method as a function parameter.
  2. Inject settingsFacades in itemDetailsFacades and send those data directly in the action.

But I’m curious if is there a more elegant method to share data between reducers.

Upvotes: 0

Views: 288

Answers (1)

J. S.
J. S.

Reputation: 2376

Normally you can just access your store to get the data. For example in an effect it would look like this

constructor(private store$: Store<AppState>) {}

@Effect() specialEffect$ = this.actions$
    .ofType(SOME_ACTION)
    .withLatestFrom(this.store$)
    .map(([action: Action, storeState: AppState]) => {
      // Do something ... use selectors, dispatch action etc.
    });

Upvotes: 1

Related Questions