使用RXJS CombineTest和管道接头防止泄漏

使用RXJS CombineTest和管道接头防止泄漏,rxjs,Rxjs,使用Rxjs时,使用管道时,takeUntil操作符如何与combinelatetest一起工作,存在一些混淆 是否有必要将takeUntil添加到每个像这样的内部观察对象,包括管道takeUntil: import {combineLatest} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; 。。。或者管道(takeUntil(this.\u destroy$)会处理combinelatetest中的内部观测值吗,如下所示:

使用Rxjs时,使用管道时,
takeUntil
操作符如何与
combinelatetest
一起工作,存在一些混淆

是否有必要将
takeUntil
添加到每个像这样的内部观察对象,包括管道
takeUntil

import {combineLatest} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

。。。或者
管道(takeUntil(this.\u destroy$)
会处理
combinelatetest
中的内部观测值吗,如下所示:

combineLatest(
      this._store.pipe(select(stateOfLocation)),
      this._store.pipe(select(stateOfPlacesSelected))
    )
      .pipe(takeUntil(this._destroy$))
      .subscribe( ([location, places])  => {
        /* Business Logic */
      });

我的猜测是后者是正确的,但我想再次检查,以确保我理解正确

根据经验法则:您只需执行一次
takeUntil
。这就是模式的要点:将其保存在一个地方


一旦您在
上下一个(…)
,销毁$,
takeUntil
保证报告完成,这反过来会触发拆卸逻辑(其中包括取消订阅)。

根据经验规则:您只需执行一次
takeUntil
。这就是模式的要点:将其保存在一个地方


一旦您在
上的
下一个(…)
上销毁$
takeUntil
保证报告完成,这反过来将触发拆卸逻辑(其中包括取消订阅).

当您在
CombineTest
之后使用
takeUntil
时,它将完成将要处理的链,并且
CombineTest
将从其所有源观测中取消订阅。当您在
CombineTest
之后使用
takeUntil
时,它将完成将要处理的链,并且
CombineTest
将取消订阅其所有源观测值。
combineLatest(
      this._store.pipe(select(stateOfLocation)),
      this._store.pipe(select(stateOfPlacesSelected))
    )
      .pipe(takeUntil(this._destroy$))
      .subscribe( ([location, places])  => {
        /* Business Logic */
      });