【发布时间】:2021-01-13 22:30:45
【问题描述】:
of([1,2,3]).subscribe(console.log)
打印:[1,2,3]
但是:
of([1,2,3]).pipe(concatAll()).subscribe(console.log)
打印:
1
2
3
为什么会出现上述情况? 为什么添加concatAll() 会一一发出数组的元素?这不是和concat这个词的意思相反吗?
我觉得concatAll() 的行为会因输入而异。
考虑一下:
from([of(1),of(2),of(3)]).pipe(concatAll()).subscribe(console.log)
它将再次打印:
1
2
3
所以of([1,2,3]).pipe(concatAll()) == from([of(1),of(2),of(3)]).pipe(concatAll())
但是of([1,2,3]) != from([of(1),of(2),of(3)]) 因为订阅后者会打印:
Observable { _isScalar: false, _subscribe: [Function] }
Observable { _isScalar: false, _subscribe: [Function] }
Observable { _isScalar: false, _subscribe: [Function] }
上面等式的右侧对我来说很清楚,但是哪里有文件证明concatAll() 应该分别发出数组的所有值,就像一个可管道的from?
【问题讨论】:
标签: rxjs rxjs6 rxjs-observables rxjs-pipeable-operators