I need know a good practise for this problem.
I am calling to three services concat with switchMaps, but I need a variable of first service for the last service. How was the best practice to do this?
Example:
this.session.account.get()
.switchMap(account => this.employerApi.get(account.accountId))
.switchMap(employer => this.addressApi.get(employer.addressId))
.filter(address => address.numer % 2)
.subscribe(address => console.log(¿¿¿¿¿account.name?????, address.name));
Thanks for your help
The simplest way would be to aggregate the values as you go:
this.session.account.get()
.switchMap(account =>
this.employerApi.get(account.accountId).map(employer => ({employer, account}))
.switchMap(data =>
this.addressApi.get(employer.addressId).map(address => ({...data, address}))
.filter(data => data.address.number % 2)
.subscribe(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With