为什么在使用 combineLatest 时不在内部可观察对象上调用运算符(tap、map)?

Why operators (tap, map) are not called on inner observable, when using combineLatest?

为什么不调用 inner observable 的运算符 tapmapcombineLatest 应该订阅它在 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]
});

工作 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;
    })
  ));
});