Skip to content

Commit 2ca7a01

Browse files
refactor: add virtual scroll repeater interface
1 parent f428c00 commit 2ca7a01

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/cdk/scrolling/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './viewport-ruler';
1414
export * from './virtual-for-of';
1515
export * from './virtual-scroll-strategy';
1616
export * from './virtual-scroll-viewport';
17+
export * from './virtual-scroll-repeater';

src/cdk/scrolling/virtual-for-of.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import {Observable, Subject, of as observableOf, isObservable} from 'rxjs';
3434
import {pairwise, shareReplay, startWith, switchMap, takeUntil} from 'rxjs/operators';
3535
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
36+
import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater';
3637

3738

3839
/** The context for an item rendered by `CdkVirtualForOf` */
@@ -74,7 +75,8 @@ function getSize(orientation: 'horizontal' | 'vertical', node: Node): number {
7475
@Directive({
7576
selector: '[cdkVirtualFor][cdkVirtualForOf]',
7677
})
77-
export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy {
78+
export class CdkVirtualForOf<T> implements
79+
CdkVirtualScrollRepeater<T>, CollectionViewer, DoCheck, OnDestroy {
7880
/** Emits when the rendered view of the data changes. */
7981
viewChange = new Subject<ListRange>();
8082

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Observable} from 'rxjs';
10+
import {ListRange} from '@angular/cdk/collections';
11+
12+
/**
13+
* An item to be repeated by the VirtualScrollViewport
14+
*/
15+
export interface CdkVirtualScrollRepeater<T> {
16+
dataStream: Observable<T[] | ReadonlyArray<T>>;
17+
measureRangeSize(range: ListRange, orientation: 'horizontal' | 'vertical'): number;
18+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import {
3434
import {auditTime, startWith, takeUntil} from 'rxjs/operators';
3535
import {ScrollDispatcher} from './scroll-dispatcher';
3636
import {CdkScrollable, ExtendedScrollToOptions} from './scrollable';
37-
import {CdkVirtualForOf} from './virtual-for-of';
3837
import {VIRTUAL_SCROLL_STRATEGY, VirtualScrollStrategy} from './virtual-scroll-strategy';
3938
import {ViewportRuler} from './viewport-ruler';
39+
import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater';
4040

4141
/** Checks if the given ranges are equal. */
4242
function rangesEqual(r1: ListRange, r2: ListRange): boolean {
@@ -131,8 +131,8 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
131131
/** The size of the viewport (in pixels). */
132132
private _viewportSize = 0;
133133

134-
/** the currently attached CdkVirtualForOf. */
135-
private _forOf: CdkVirtualForOf<any> | null;
134+
/** the currently attached CdkVirtualScrollRepeater. */
135+
private _forOf: CdkVirtualScrollRepeater<any> | null;
136136

137137
/** The last rendered content offset that was set. */
138138
private _renderedContentOffset = 0;
@@ -215,8 +215,8 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
215215
super.ngOnDestroy();
216216
}
217217

218-
/** Attaches a `CdkVirtualForOf` to this viewport. */
219-
attach(forOf: CdkVirtualForOf<any>) {
218+
/** Attaches a `CdkVirtualScrollRepeater` to this viewport. */
219+
attach(forOf: CdkVirtualScrollRepeater<any>) {
220220
if (this._forOf) {
221221
throw Error('CdkVirtualScrollViewport is already attached.');
222222
}

0 commit comments

Comments
 (0)