From a7181401eabf8beac51298bcff5bd88a1759d17f Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Tue, 27 Feb 2018 14:18:03 -0800 Subject: [PATCH 1/2] virtual-scroll: switch throttleTime to sampleTime --- src/cdk-experimental/scrolling/virtual-scroll-viewport.ts | 4 ++-- tools/package-tools/rollup-globals.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts b/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts index 3a532814525d..d8710c64058c 100644 --- a/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts +++ b/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts @@ -22,8 +22,8 @@ import { } from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {fromEvent} from 'rxjs/observable/fromEvent'; +import {sampleTime} from 'rxjs/operators/sampleTime'; import {takeUntil} from 'rxjs/operators/takeUntil'; -import {throttleTime} from 'rxjs/operators/throttleTime'; import {animationFrame} from 'rxjs/scheduler/animationFrame'; import {Subject} from 'rxjs/Subject'; import {CdkVirtualForOf} from './virtual-for-of'; @@ -177,7 +177,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy { this._ngZone.runOutsideAngular(() => { fromEvent(this.elementRef.nativeElement, 'scroll') - .pipe(throttleTime(0, animationFrame)) + .pipe(sampleTime(0, animationFrame)) .subscribe(() => this._scrollStrategy.onContentScrolled()); }); }); diff --git a/tools/package-tools/rollup-globals.ts b/tools/package-tools/rollup-globals.ts index 0893410efdc1..bc2ff8954669 100644 --- a/tools/package-tools/rollup-globals.ts +++ b/tools/package-tools/rollup-globals.ts @@ -71,6 +71,8 @@ export const rollupGlobals = { 'rxjs/observable/of': 'Rx.Observable', 'rxjs/observable/throw': 'Rx.Observable', + 'rxjs/scheduler/animationFrame': 'Rx.Scheduler', + 'rxjs/operators/auditTime': 'Rx.operators', 'rxjs/operators/catchError': 'Rx.operators', 'rxjs/operators/combineLatest': 'Rx.operators', @@ -81,6 +83,7 @@ export const rollupGlobals = { 'rxjs/operators/first': 'Rx.operators', 'rxjs/operators/map': 'Rx.operators', 'rxjs/operators/pairwise': 'Rx.operators', + 'rxjs/operators/sampleTime': 'Rx.operators', 'rxjs/operators/share': 'Rx.operators', 'rxjs/operators/shareReplay': 'Rx.operators', 'rxjs/operators/startWith': 'Rx.operators', From 578f40f1cb319bb863f4758c58ea1f75a2502e0d Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 28 Feb 2018 09:11:39 -0800 Subject: [PATCH 2/2] add comment --- src/cdk-experimental/scrolling/virtual-scroll-viewport.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts b/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts index d8710c64058c..ce4f8dc3a11e 100644 --- a/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts +++ b/src/cdk-experimental/scrolling/virtual-scroll-viewport.ts @@ -177,6 +177,8 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy { this._ngZone.runOutsideAngular(() => { fromEvent(this.elementRef.nativeElement, 'scroll') + // Sample the scroll stream at every animation frame. This way if there are multiple + // scroll events in the same frame we only need to recheck our layout once .pipe(sampleTime(0, animationFrame)) .subscribe(() => this._scrollStrategy.onContentScrolled()); });