如何解决是否可以避免嵌套订阅?
我正在使用 angular 和 rxJS
我对 rxJS
运算符很陌生,无法找到将所有内容保留在流中的方法。
我的直播很长,所以我会直截了当地解释我正在处理的问题
我需要运行可多次触发的 parralel Observables
并以相同的方式处理它们的数据,但它们的订阅需要按特定顺序排列。例如
firstObservable$.pipe(
map(() => secondObservable$),//this will only be triggered once
tap(value => doSomething(value)),//data is processed once following the stream
mergeMap(() => ThirdObservable$),//this one will be triggered multiple times but is subscribed in a particular order
tap(value => doAnotherThing(value)),//how can I attach the processing og data to the observable?
mergeMap(() => FourthObservable$),//this one will be triggered multiple times but is subscribed in a particular order
tap(value => andAnother(value)),//how can I attach the processing og data to the observable?
map(() => FifthObservable$),//this will only be triggered once
tap(value => again(value))//data is processed once following the stream
).subscribe()
现在我的问题是,如果 ThirdObservable$
被第二次触发,它将继续流的其余部分并调用 FourthObservable$
和 FifthObservable$
我想要相当于
firtsObservable$.subscribe( // triggered Once
(value) => secondObservable$.subscribe( // triggered Once
(secondValue) => {
processSecondValueOnce(secondValue)
ThirdObservable$.subscribe(thirdValue => process(thirdValue)) // this can be triggered multiple times
fourthObservable$.subscribe(fourthValue => process(fourthValue)) // this can be triggered multiple times
fifthObservable$.subscribe( // triggered Once
(fifthValue) => {
process(fifthValue)
}
)
}
)
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。