DEV Community

Discussion on: Ditch Subscriptions, Use the Power of rxjs instead

Collapse
 
paulmojicatech profile image
paulmojicatech

Hi Thorsten. In rxjs, you use the ‘.pipe’ orchestrate asynchronous events. You can take the response, pass it into an operator, do some transformation, and pass a new objects to another operator where you can do another transformation or call another asynchronous event. Take the following example: you need to populate your component with an adddress. You compose the address based on 2 API calls, one to get the address and another to get a list of countries. The pattern I have been using is I have a method in my service the will return an observable of the data (view model) my components need. In this situation, I would call the API to get the address, run it through .pipe call switchMap to call the other API, and transform the response to orchestrate the data from both APIs to one object that the method returns. Pleas see Stackblitz here: