Below My code works well.
But, I think combineLatest
in other observable
($fromArray)'s operator (map) is weird.
How can I make combineLatest
as observable
itself?
const item = ["television", "pc", "radio", "camera"];
const fooMarket = webSocket("wss://api.fooMarket.com/websocket/");
const barMarket = webSocket("wss://api.barMarket.com/websocket/");
// market WS unit Stream is like below (emit real-time price change for each Item, but Arbitrary Item Emission)
// {
// itemName : "televison",
// price: 980
// }
const fromArray$ = of(...item).pipe(
map((x) => {
const fooItem = fooMarket.pipe(
filter((y) => y.itemName === x),
map((z) => ({ itemName, price: item.price }))
);
const barItem = barMarket.pipe(
filter((y) => y.itemName === x),
map((z) => ({ itemName, price: item.price }))
);
combineLatest({ [`foo-${x}`]: fooItem, [`var-${x}`]: barItem }).subscribe(
console.log
);
// return combineLatest({ [`foo-${x}`]: fooItem, [`var-${x}`]: barItem }).subscribe; // this way makes fromArray$'s type as 'Subscription' (not 'Observable' type)
})
);
fromArray$.subscribe();
// result is like below
// {
// "foo-television": { itemName : "television", price: 980 },
// "bar-television : { itemName : "television", price: 950 }
// }
// {
// "foo-pc": { itemName : "pc", price: 110 },
// "bar-pc : { itemName : "pc", price: 120 }
// }
// ...continuing as Real-time Price Change