しかし:
なぜ演算子であるtap
とmap
、内部観測可能ではないと呼ばれますか?combineLatest
それはに入った観測に加入しなければならないobsArr
、右?なぜ、このサブスクリプションは、これらの演算子をトリガしませんか?
const obsArr = [];
[[1, 2], [3, 4], [5, 6]].map(arr => {
const observable = from(arr);
observable.pipe(
tap(item => {
// this is NOT called
console.log('tap', item)
}),
map(item => {
// this is NOT called
return item * -1;
})
);
obsArr.push(observable);
});
combineLatest(obsArr).subscribe(latestValues => {
console.log(latestValues);
// LOG: [2, 4, 5]
// LOG: [2, 4, 6]
});
ワーキングstackblitz:https://rxjs-y2h4rn.stackblitz.io
説明してくれてありがとう!
イライジャ・スミス:
問題は、あなたが観測可能にパイプを追加することが、配列に、元の観測を推進しているということです。代わりに、変更し、観察をプッシュする必要があります。
[[1, 2], [3, 4], [5, 6]].map(arr => {
const observable = from(arr);
obsArr.push(observable.pipe(
tap(item => {
console.log('tap', item)
}),
map(item => {
return item * -1;
})
));
});