Skip to content
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

feat(data-table): allow dynamic data source #5093

Merged
merged 4 commits into from
Jun 16, 2017

Conversation

andrewseguin
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 12, 2017
@Input()
get dataSource(): DataSource<T> { return this._dataSource; }
set dataSource(dataSource: DataSource<T>) {
if (this._dataSource == dataSource) { return; }

Choose a reason for hiding this comment

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

triple equals?

}

ngOnDestroy() {
// TODO(andrewseguin): Disconnect from the data source so
// that it can unsubscribe from its streams.
this._onDestroy.next();

Choose a reason for hiding this comment

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

I believe you want to complete the subject so it won't emit anymore and the datasource listener will also finish.

this._onDestroy.complete();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it goes either way, according to this documentation: If this second Observable emits an item or sends a termination notification, the Observable returned by TakeUntil stops mirroring the source Observable and terminates.

Though I do agree that complete() looks nicer and more definitive, will change to that.

}

/**
* Create the embedded view for the header template and place it in the header row view container.
*/
renderHeaderRow() {
const cells = this.getHeaderCellTemplatesForRow(this._headerDefinition);
_renderHeaderRow() {

Choose a reason for hiding this comment

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

Can this be marked private? Or is it used somewhere else? Ditto to some of the other methods in this class.

get dataSource(): DataSource<T> { return this._dataSource; }
set dataSource(dataSource: DataSource<T>) {
if (this._dataSource == dataSource) { return; }
this._data = [];
Copy link
Member

Choose a reason for hiding this comment

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

Can you move most of this setter out into a separate function like _updateDataSource or _switchDataSource?

// Re-render the rows if any of their columns change.
// TODO(andrewseguin): Determine how to only re-render the rows that have their columns changed.
const rowColumnsChange =
this._rowDefinitions.toArray().map((rowDef: BaseRowDef) => rowDef.columnsChange);
Copy link
Member

Choose a reason for hiding this comment

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

QueryList has a map function so you don't need toArray
https://angular.io/api/core/QueryList

You also shouldn't need a type in the map function since it is given by the generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks

@@ -161,7 +145,7 @@ export class CdkTable<T> implements CollectionViewer {
}

ngOnDestroy() {
this._onDestroy.next();
this._onDestroy.complete();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think next() is still required for takeUntil(example)

I suspect @ErinCoughlan was suggesting you use both

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the heads up, I appreciate the plunker to help me understand. Looking at the RxJS code does indicate that it doesn't look to the completion event.

Returns the values from the source observable sequence until the other observable sequence produces a value.

This doesn't line up with the documentation from reactivex.io which says that either an emitted value or termination notification would end it.

Will change it to be next() and complete(). Not totally sure the complete() is necessary but we can discuss another time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the rxjs docs will eventually be updated to reflect behavior being inconsistent with reactivex.io ReactiveX/rxjs#2160

Also don't think complete() is required, but as far as I've seen, this SO answer has been the recommended approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM, thanks for the context. We'll have to continue looking at this for other components where we want to unsubscribe on destroy

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jun 14, 2017
@kara kara merged commit e55ec78 into angular:master Jun 16, 2017
@andrewseguin andrewseguin deleted the table-data-source-setter branch November 28, 2017 20:35
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants