DataSource for mat-table and CDK should just be an Observable<T[]> or even T[]
See original GitHub issueThe current contract for a DataSource
is simply:
interface DataSource<T> {
connect(): Observable<T[]>;
disconnect(): void
}
I propose that it would be either just Observable<T[]>
or perhaps better: T[]
.
What i don’t know
What is disconnect()
really used for? It seems like it’s just meant to tear down data producers and resources.
It’s currently unergonomic
Currently when trying to use mat-table
with ngrx, I’m force to wrap the selected state observable for no real gain, and it’s very unergonomic as a developer. Similarly, if all I wanted to do was get a simple array of data via AJAX, it would be dead simple if dataSource
accepted an Observable<T[]>
instead of the current abstraction.
Maybe it could be an Observable<T[]>
I submit that since the Observable<T[]>
must be subscribed to, and that the Subscription
it returns has a “disconnect” semantic via unsubscribe(): void
, that the DataSource
is an unnecessary abstraction.
Maybe it could just be T[]
It might be even easier if the table simply accepted an array of data, because fundamentally, there isn’t much difference between having Angular subscribe with [data]="someData$ | async"
and having the component itself do the subscribing, with the exception that if the component is doing all of the subscription management, rather than async pipe, you’ve got a lot of extra code in your component you don’t need.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:9 (2 by maintainers)
Top GitHub Comments
I couldn’t find any documentation for
CollectionViewer
, except the documentation comments in the source code, which are of almost no help. Perhaps, extensive documentation could make me change my mind.However, as for now, it seems to be absolutely weird to me to enforce using an additional layer of
DataSource<T>
instead of usingObservable<T[]>
directly. It is a real pain! For example, it’s impossible to usepipe
s against the observable in a component template. Any data modifications have to be done by theDataSource
itself, andconnect()
has to return a completely finished stream of data.Something has to be changed here indeed 😃
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.