当第一个mergeMap
返回空数组时,是否可以使其返回一个操作(已完成)?
of(1)
.pipe(
mergeMap(x => []), // this can result in empty array
distinct(),
mergeMap(x => {
...
return fulfilled()
})
)
.subscribe((x) => console.log(x));
不要返回一个空数组,而是返回一个发出单个哨兵值的 observable。
const SENTINEL = Symbol();
of(1)
.pipe(
mergeMap((x) => of(SENTINEL)),
distinct(),
mergeMap((x) => {
if (x === SENTINEL) return fulfilled();
// etc.
})
)
.subscribe((x) => console.log(x));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句