Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(template): add DataSource support for rx-virtual-for directive #1764

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

friendlyAce
Copy link
Contributor

@friendlyAce friendlyAce commented Aug 31, 2024

Proposal
Link to feature request: #1765

Currently, the rx virtual for directive supports rendering from signal, observable and static iterables. This proposal aims to extends the functionality by adding support for the DataSource interface that is supported in the CdkVirtualForOf of the Angular CDK. The rx virtual for directive could directly connect to and disconnect from the given DataSource when needed.

This PR introduces support for DataSource in rx-virtual-for, aligning with Angular CDK's implementation while leveraging rx-angular's powerful reactive approach.

When users want to use their existing data source implementations they will need to implement the CollectionViewer interface at the component that uses rx virtual for and link the viewRange: ListRange output of that virtual for directive to their DataSource implementation for connecting and passing the returned Observable to rxVirtualFor and handle disconnecting from that data source when needed.

Key features:

  • Implement DataSource interface compatible with rx-virtual-for
  • Add support for DataSource input in the rxVirtualForOf directive
  • Enhance the rxVirtualForOf to handle the DataSource input case, the connection to and disconnection from the data source

Benefits:

  • Improved compatibility with te existing Angular CDK patterns
  • Enhanced flexibility for data handling in virtual scrolling scenarios
  • Better integration with complex data fetching and manipulation use cases (lazy on demand requesting data, filtering, etc.)

Implementation details:

  • Modified rxVirtualForOf input to accept DataSource
  • Add use-case to check whether the input is a data source
  • Updated internal logic to connect to the DataSource using the current ListRange and disconnect from the DataSource when destroyed

Documentation:

  • Needs to be added if the feature proposal is desired (apps\docs\docs\template\api\virtual-scrolling.mdx)

In addition to the implementation details mentioned above, I have declared the necessary types such as DataSource, CollectionViewer, and the isDataSource method within the rx-angular template package itself.

This approach eliminates the need for a (peer) dependency on Angular CDK, ensuring that rx-virtual-for remains self-contained and independent, similar how it was done with the ListRange interface.

Feedback, concerns, improvements are more than welcome

BR,
Vincent

@github-actions github-actions bot added </> Template @rx-angular/template related 🔬 Experimental Experimental: Feature, docs, demos labels Aug 31, 2024
Copy link

nx-cloud bot commented Aug 31, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit b00b41d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@hoebbelsB
Copy link
Member

hey @friendlyAce thanks a lot for your contribution! Will make a review over the weekend!

@@ -251,6 +255,21 @@ export class RxVirtualFor<T, U extends NgIterable<T> = NgIterable<T>>
this.observables$.next(
toObservable(potentialSignalOrObservable, { injector: this.injector }),
);
} else if (this.isDataSource(potentialSignalOrObservable)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be potentialSignalOrObservableOrDataSource now? :)

@@ -34,6 +34,17 @@ export interface ListRange {
end: number;
}

export abstract class DataSource<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know if it's possible to maybe have an import type { DataSource } from '@angular/cdk' without having it to mention as peerDependency?

That would be the absolute best case

Comment on lines +270 to +272
this._destroy$.pipe(take(1)).subscribe(() => {
potentialSignalOrObservable.disconnect(collectionViewer);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not a big fan of that. We should do the disconnect in ngOnDestroy.

Comment on lines +293 to +294
value !== null &&
value !== undefined &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this be shortened with value != null?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔬 Experimental Experimental: Feature, docs, demos </> Template @rx-angular/template related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants