我可以通过 return 结果在 combineLatest 中订阅吗?
Can I subscribe inside the combineLatest by the return result?
我想使用 combineLatest 来获得一堆结果。然后将其中一个结果作为输入参数传递给另一个订阅调用。
combineLatest([first, second, third, four, five]).pipe(take(1)).
subscribe(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
if(e > 8) {
this.myService.updateStatus(e).subscribe(
result => this.setupStatus(result)
);
}
});
逻辑来自5个结果,其中4个用于渲染屏幕。最后一个我是用它来订阅的,它的返回结果会用到一些地方。
但我觉得不对,因为有时this.setupStatus(result)
在combineLatest
里面好像不是运行。内存泄漏?
很难诊断为什么它不会 运行 如果不了解更多关于可观察量的信息。但我会这样做以避免嵌套订阅并使其更容易诊断/管理:
combineLatest([first, second, third, four, five]).pipe(
take(1),
switchMap(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
return this.myService.updateStatus(e);
})
).subscribe(result => this.setupStatus(result));
根据我希望事情发生的确切时间,结构可能会有所不同。
我想使用 combineLatest 来获得一堆结果。然后将其中一个结果作为输入参数传递给另一个订阅调用。
combineLatest([first, second, third, four, five]).pipe(take(1)).
subscribe(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
if(e > 8) {
this.myService.updateStatus(e).subscribe(
result => this.setupStatus(result)
);
}
});
逻辑来自5个结果,其中4个用于渲染屏幕。最后一个我是用它来订阅的,它的返回结果会用到一些地方。
但我觉得不对,因为有时this.setupStatus(result)
在combineLatest
里面好像不是运行。内存泄漏?
很难诊断为什么它不会 运行 如果不了解更多关于可观察量的信息。但我会这样做以避免嵌套订阅并使其更容易诊断/管理:
combineLatest([first, second, third, four, five]).pipe(
take(1),
switchMap(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
return this.myService.updateStatus(e);
})
).subscribe(result => this.setupStatus(result));
根据我希望事情发生的确切时间,结构可能会有所不同。