Skip to content

Commit 78f2e2a

Browse files
committed
virtual-scroll: switch throttleTime to sampleTime (#10179)
* virtual-scroll: switch throttleTime to sampleTime * add comment
1 parent 3dfdc3b commit 78f2e2a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/cdk-experimental/scrolling/virtual-scroll-viewport.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
} from '@angular/core';
2323
import {Observable} from 'rxjs/Observable';
2424
import {fromEvent} from 'rxjs/observable/fromEvent';
25+
import {sampleTime} from 'rxjs/operators/sampleTime';
2526
import {takeUntil} from 'rxjs/operators/takeUntil';
26-
import {throttleTime} from 'rxjs/operators/throttleTime';
2727
import {animationFrame} from 'rxjs/scheduler/animationFrame';
2828
import {Subject} from 'rxjs/Subject';
2929
import {CdkVirtualForOf} from './virtual-for-of';
@@ -177,7 +177,9 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
177177

178178
this._ngZone.runOutsideAngular(() => {
179179
fromEvent(this.elementRef.nativeElement, 'scroll')
180-
.pipe(throttleTime(0, animationFrame))
180+
// Sample the scroll stream at every animation frame. This way if there are multiple
181+
// scroll events in the same frame we only need to recheck our layout once
182+
.pipe(sampleTime(0, animationFrame))
181183
.subscribe(() => this._scrollStrategy.onContentScrolled());
182184
});
183185
});

tools/package-tools/rollup-globals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export const rollupGlobals = {
7171
'rxjs/observable/of': 'Rx.Observable',
7272
'rxjs/observable/throw': 'Rx.Observable',
7373

74+
'rxjs/scheduler/animationFrame': 'Rx.Scheduler',
75+
7476
'rxjs/operators/auditTime': 'Rx.operators',
7577
'rxjs/operators/catchError': 'Rx.operators',
7678
'rxjs/operators/combineLatest': 'Rx.operators',
@@ -81,6 +83,7 @@ export const rollupGlobals = {
8183
'rxjs/operators/first': 'Rx.operators',
8284
'rxjs/operators/map': 'Rx.operators',
8385
'rxjs/operators/pairwise': 'Rx.operators',
86+
'rxjs/operators/sampleTime': 'Rx.operators',
8487
'rxjs/operators/share': 'Rx.operators',
8588
'rxjs/operators/shareReplay': 'Rx.operators',
8689
'rxjs/operators/startWith': 'Rx.operators',

0 commit comments

Comments
 (0)