Reputation: 544
Using a redux architecture and Observables, I am in a situation when I need to process data after fetching different asynchronous sources.
This is how it is supposed to work:
This seems to work well, but I am not quite sure it is the right way to do.
What is the preferred implementation in this scenario? How would you unsubscribe services and/or access to store? How do you instantiate your observables or subjects?
I am looking here for any best practice or pattern.
Upvotes: 0
Views: 141
Reputation: 544
With a bit more experience on the subject, the answer now seems clear: use Effects.
As API calls are side-effects, your effects can quietly request the data and wait with a combineLatest
in order to combine the different datasets.
When this is done, and still in the effect, you can dispatch an action to store the data.
Then, a selector linked to the processed data will provide data to the component.
Upvotes: 0
Reputation: 60596
Are you using NgRx? I assume so since that is the library that implements the redux pattern.
I often find with NgRx that I don't need to implement my own Subject/BehaviorSubject and instead build selectors.
You could build a selector that combines the desired set of data so that the component can simply get the data without having to know about the structure of the store.
Upvotes: 3