Skip to content

feat(cdk/collections): extract view repeater strategies #19964

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

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

MichaelJamesParsons
Copy link
Collaborator

A ViewRepeater implements a strategy for rendering a list of elements inside a common ViewContainerRef. It encapsulates all the business logic pertaining to inserting, moving, and deleting embedded views. This PR extracts existing strategies from virtualForOf and the CDK table, so we can reuse them in upcoming virtual scroll work.

Summary

  • Extracts view repeater strategies from virtualForOf and CDK table.
  • Refactors virtualForOf and CDK table to use the strategies.
  • With the exception of extracting the view repeater strategies, no behavior has changed.

For now, this API will be internal until we've tested it with enough components to know it's stable.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 13, 2020
@MichaelJamesParsons MichaelJamesParsons added area: cdk/collections G This is is related to a Google internal issue labels Jul 13, 2020
@jelbourn jelbourn added the target: minor This PR is targeted for the next minor release label Jul 14, 2020
@MichaelJamesParsons MichaelJamesParsons force-pushed the view-repeaters branch 3 times, most recently from 0706a2a to f8f33eb Compare July 14, 2020 01:06
@MichaelJamesParsons MichaelJamesParsons force-pushed the view-repeaters branch 3 times, most recently from 5ea2236 to 7e50f47 Compare July 14, 2020 04:25
@MichaelJamesParsons MichaelJamesParsons requested a review from a team as a code owner July 14, 2020 04:25
providers: [{provide: CDK_TABLE, useExisting: CdkTable}]
providers: [
{provide: CDK_TABLE, useExisting: CdkTable},
{provide: _VIEW_REPEATER_STRATEGY, useClass: DisposeViewRepeaterStrategy},
Copy link
Member

Choose a reason for hiding this comment

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

Providing this directly might still end up with the problem of always including the code for DisposeViewRepeaterStrategy even when it's not being used. Is this a temporary thing until we have a directive API for switching between rending strategies?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is temporary. The virtual scroll table PR will introduce a directive-based API to replace it.

Copy link
Member

Choose a reason for hiding this comment

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

Cool- can you add a TODO here to make that explicit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Jul 23, 2020
@MichaelJamesParsons MichaelJamesParsons force-pushed the view-repeaters branch 2 times, most recently from ae357b4 to 8b99d2c Compare July 23, 2020 19:09
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Jul 23, 2020
@MichaelJamesParsons MichaelJamesParsons force-pushed the view-repeaters branch 2 times, most recently from 29e13bf to a02a01e Compare July 23, 2020 22:38
@MichaelJamesParsons
Copy link
Collaborator Author

The failing tests are related to the MDC MatSlider. The changes made in this PR shouldn't have impacted them.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

*/
export class _RecycleViewRepeaterStrategy<T, R, C extends _ViewRepeaterItemContext<T>>
implements _ViewRepeater<T, R, C> {
differ: IterableDiffer<C>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere? I don't see it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The differ was abstracted out of the repeater strategy. I'll remove it.

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 aside from minor remaining comments; I'll leave it to @mmalerba for final approval

get cdkVirtualForTemplateCacheSize() {
return this._viewRepeater.viewCacheSize;
}
set cdkVirtualForTemplateCacheSize(size: number | string) {
Copy link
Member

Choose a reason for hiding this comment

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

This should just be number, and you can add this to the bottom of this class to tell Angular to accept other data types:

static ngAcceptInputType_cdkVirtualForTemplateCacheSize: NumberInput;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@MichaelJamesParsons
Copy link
Collaborator Author

@mmalerba The latest revisions are complete.

@jelbourn
Copy link
Member

@MichaelJamesParsons looks like the PR just needs to be rebased

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker P2 The issue is important to a large percentage of users, with a workaround labels Jul 27, 2020
@mmalerba
Copy link
Contributor

Looks like there's a lint issue that needs to be fixed, otherwise ready to go

@MichaelJamesParsons
Copy link
Collaborator Author

@jelbourn @mmalerba All fixed

@jelbourn
Copy link
Member

@googlebot ping

@jelbourn jelbourn merged commit 3b3b55f into angular:master Jul 29, 2020
@MichaelJamesParsons MichaelJamesParsons deleted the view-repeaters branch July 30, 2020 19:06
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 26, 2020
In angular#19964 and angular#19750 some breaking constructor changes were made which eventually got released as a part of a patch branch which doesn't follow our breaking changes policy.

These changes make the new constructor parameters optional and add fallbacks to the old behavior.

Fixes angular#20422.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 26, 2020
In angular#19964 and angular#19750 some breaking constructor changes were made which eventually got released as a part of a patch branch which doesn't follow our breaking changes policy.

These changes make the new constructor parameters optional and add fallbacks to the old behavior.

Fixes angular#20422.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 27, 2020
In angular#19964 and angular#19750 some breaking constructor changes were made which eventually got released as a part of a patch branch which doesn't follow our breaking changes policy.

These changes make the new constructor parameters optional and add fallbacks to the old behavior.

Fixes angular#20422.
@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 Aug 30, 2020
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 area: cdk/collections cla: yes PR author has agreed to Google's Contributor License Agreement G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants