Let's say I have a observable coming in, something like this below. Here, company
has a method website
. I'd like to add a new property to this object called websiteStatusCode
that is a number. The value of websiteStatusCode
the status code for the website. I have to make an HTTP request to the server and I want to store the status code. We have a request
promise that returns response.statusCode
.
companyStream.map(company => {
// company.website
})
Do I simply open the promise within the map? Do I have to wrap the promise within a Rx.Observable.fromPromise
and return that?
companyStream.map(company => {
if (!company.website) {
company.websiteStatusCode = false
return company
}
return Rx.Observable.fromPromise(request(company.website).then(request => {
company.websiteStatusCode = request.statusCode
return company
}))
})
Is this valid code above? Is there a better way to tap into object properties with Rx that's not so verbose?