【发布时间】:2020-06-25 00:03:43
【问题描述】:
为什么不调用内部 observable 的运算符 tap 和 map? combineLatest 应该订阅它在 obsArr 中获得的 observables,对吗?为什么这个订阅不会触发那些操作符?
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]
});
工作堆栈闪电战:https://rxjs-y2h4rn.stackblitz.io
感谢解释!
【问题讨论】:
标签: javascript typescript rxjs rxjs-pipeable-operators rxjs-observables