This title probably needs more explanation.
Basically what I get from the backend is an Observable with an array of racedrivers, and to each of the array items, I want to map another property isOnTrack, which consists of another Observable (simple boolean) I retrieve from the backend. I want to flatten the end result so I don't have an Observable within an Observable. I've tried many of the rxjs operators but I cannot get it to work.
Code that doesn't work:
this.drivers$ = this.db.list('users').valueChanges().pipe(
map(arr => arr.map( (driver:any) => {
driver.isOnTrack = this.db.object(`telemetry/${driver.uid}/values/IsOnTrack`).valueChanges();
return driver
})),
mergeAll()
);
This successfully maps the isOnTrack observable to the array items but I can't get it flattened.
Project is on RxJS 6
Update 1
After Jonathan's answer I believe I should have used the word unpacked instead of flattening
The Observable after transformations that I would be looking for should deliver something similar to
of([
{id: 1, name: 'foo', isOnTrack: true},
{id: 2, name: 'bar', isOnTrack: true},
{id: 3, name: 'baz', isOnTrack: false},
])
and after one IsOnTrack is changed in the backend it should emit the complete array again.
of([
{id: 1, name: 'foo', isOnTrack: false},
{id: 2, name: 'bar', isOnTrack: true},
{id: 3, name: 'baz', isOnTrack: false},
])