我怎样才能防止 CombineLatest 第一次触发

how can i prevent CombineLatest to fire the first time

我有一个带有一堆字段的表单(使用 reactiveForm)。 当字段A或B的值发生变化时,我想执行doStuffWithAnB。

所以 combineLatest 似乎是我需要的。

combineLatest(A.valueChanges,B.valueChanges).subscribe(doStuffWithAnB)

现在,如果用户进入表单,并且只触及 B(或 A),我想执行我的功能,> startWith

combineLatest(A.valueChanges.pipe(startWith(someDefaultValue),B.valueChanges.pipe(startWith(someOtherDefaultValue)).subscribe(doStuffWithAnB)

但是现在 doStuffWithAnB 从一开始就被触发了,因为我的 2 个流都有一个 startWith,但是我不想在其中一个字段被修改之前执行 doStuffWithAnB

我怎样才能以干净的方式实现它?

为什么不选择 merge 而不是其中一个结果!我们也不需要 startsWith,因为它最初不应该执行!

发件人:

 combineLatest(A.valueChanges.pipe(startWith(someDefaultValue),B.valueChanges.pipe(startWith(someOtherDefaultValue)).subscribe(doStuffWithAnB)

收件人:

merge(A.valueChanges,B.valueChanges).subscribe(doStuffWithAnB)