I am currently working with an observable that streams an array of food items. For each item, I need to retrieve the latest information on the cook, kitchen, and knife used in its preparation. These values are obtained from separate observables like getCookById(food.cook.id).
- I want to wait for the array of food items to be received
- Once I have the array, I need to map over each food item and:
- Retrieve the latest information on the cook, kitchen, and knife (possibly using combineLatest)
- Combine these values into an object structure like:
{
foodItem,
cook,
kitchen,
knife
}
Currently, my implementation is resulting in an array of empty items:
const foodObservable = new Subject();
foodObservable.pipe(
map(foodItems => {
return foodItems.map((foodItem: any)=>{
const cookObservable = new Subject();
const kitchenObservable = new Subject();
const knifeObservable = new Subject();
combineLatest(cookObservable, kitchenObservable, knifeObservable).subscribe(([cook, kitchen, knife]) => {
return {
foodItem,
cook,
kitchen,
knife
};
});
})
})
).subscribe(foodPreparationArray=>{
console.log(foodPreparationArray) // array of empty values :(
})