我在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,但我不知道该怎么做,有什么想法吗?
该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)
归档时间: |
|
查看次数: |
1539 次 |
最近记录: |