多个RXJS BehaviorSubjects触发函数调用

我想运行一个依赖于3 behaviorSubjects的最新值的计算密集型函数。有时所有的科目都会同时变化,我不想重复计算3次。这就是我到目前为止实现它的方式。

this.subscription = merge(behaviorSubject1$, behaviorSubject2$, behaviorSubject3$)
        .pipe(throttleTime(300)) //this is to avoid running the function 3 times when all subjects change simultaneously
        .subscribe(() => {
           const answer = getSolution(subject1$.getValue(), subject2$.getValue(), subject3$.getValue());

        });

我不确定这是否是最好的方式。任何帮助都是非常感谢的。

转载请注明出处:http://www.shenzhenzsmy.com/article/20230526/2413648.html