Skip to content

feat(cdk/scrolling): update CdkVirtualForOf to work with sets. #20594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cdk/scrolling/virtual-for-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export class CdkVirtualForOf<T> implements
if (isDataSource(value)) {
this._dataSourceChanges.next(value);
} else {
// Slice the value if its an NgIterable to ensure we're working with an array.
// If value is an an NgIterable, convert it to an array.
this._dataSourceChanges.next(new ArrayDataSource<T>(
isObservable(value) ? value : Array.prototype.slice.call(value || [])));
isObservable(value) ? value : Array.from(value || [])));
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/cdk/scrolling/virtual-scroll-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('CdkVirtualScrollViewport', () => {
.toBe(0, 'should render from first item');
}));

it('should handle dynamic item array keeping position when possibile', fakeAsync(() => {
it('should handle dynamic item array keeping position when possible', fakeAsync(() => {
testComponent.items = Array(100).fill(0);
finishInit(fixture);
triggerScroll(viewport, testComponent.itemSize * 50);
Expand Down Expand Up @@ -516,6 +516,15 @@ describe('CdkVirtualScrollViewport', () => {
}
}));

it('should work with a Set', fakeAsync(() => {
const data = new Set(['hello', 'world', 'how', 'are', 'you']);
testComponent.items = data as any;
finishInit(fixture);

expect(viewport.getRenderedRange())
.toEqual({start: 0, end: 4}, 'newly emitted items should be rendered');
}));

it('should work with an Observable', fakeAsync(() => {
const data = new Subject<number[]>();
testComponent.items = data as any;
Expand Down