question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataSource for mat-table and CDK should just be an Observable<T[]> or even T[]

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Maximaximumcommented, Dec 12, 2017

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 using Observable<T[]> directly. It is a real pain! For example, it’s impossible to use pipes against the observable in a component template. Any data modifications have to be done by the DataSource itself, and connect() has to return a completely finished stream of data.

Something has to be changed here indeed 😃

0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the MatTableDataSource with an observable?
You should be able to new up the MatTableDataSource once at the class level and then use the data setter in ngOnInit ....
Read more >
Angular Material Data Table: A Complete Example
A complete example of an Angular Material Data Table with server-side pagination, sorting, filtering, as well as a loading indicator.
Read more >
Table | Angular Material
The CdkTable is an unopinionated, customizable data-table with a fully-templated API, dynamic columns, and an accessible DOM structure.
Read more >
Angular CDK Tables - Medium
This tableDataSource$ will serve as our DataSource input for our Angular CDK Table. ... headers a click event that will adjust our sorting...
Read more >
Beautifully encapsulate table related logic using a custom ...
How to implement a custom data source for a table in Angular. ... Then we have an event that will be emitted when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found