Skip to content

[virtual-scroll]: collectionViewer.viewChange is emitted only after the observable returned from DataSource#connect has been emitted once #14589

@kimamula

Description

@kimamula

What is the expected behavior?

The following implementation of DataSource#connect should work.

connect(collectionViewer: CollectionViewer): Observable<ProjectListItem[]> {
  return collectionViewer.viewChange.pipe(
    switchMap(({ start, end }) => this.fetchData(start, end))
  );
}

What is the current behavior?

The above code does not work while the following works.

connect(collectionViewer: CollectionViewer): Observable<ProjectListItem[]> {
  return collectionViewer.viewChange.pipe(
    startWith({ start: 0, end: 0 }), // add this line
    switchMap(({ start, end }) => this.fetchData(start, end))
  );
}

IMO this behavior is really confusing.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-nzrgbv?file=app%2Fcdk-virtual-scroll-data-source-example.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: cdk/scrolling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions