angular2:如何去除Observable.combine最新的电话?

art*_*urh 7 rxjs angular

我在angular2应用程序中遇到了性能问题,因为我有一个很大的Observable.combineLatest(),其中有许多输入快速变化,我想要去掉回调调用:

myData$ = Observable.combineLatest(
  this.store.let(fromRoot.getFoo),
  this.store.let(fromRoot.getBar),
  this.store.let(fromRoot.getFoobar),
  this.store.let(fromRoot.getBarfoo),
  (foo, bar, foobar, barfoo) => {
     ...
  });
Run Code Online (Sandbox Code Playgroud)

事后调用debounce,例如Observable.combineLatest(...).debounceTime(300),是无用的,因为CPU密集型任务发生在仍然经常被调用的combineLatest回调中.

我想我必须结合另一个Observable,但我不知道该怎么做,有什么想法吗?

car*_*ant 9

combineLatest方法的project功能本质上是一个map操作符.你可以重新安排这样的事情:

myData$ = Observable.combineLatest(
  this.store.let(fromRoot.getFoo),
  this.store.let(fromRoot.getBar),
  this.store.let(fromRoot.getFoobar),
  this.store.let(fromRoot.getBarfoo)
)
.debounceTime(300)
.map(([foo, bar, foobar, barfoo]) => {
  ...
});
Run Code Online (Sandbox Code Playgroud)