Skip to content

fix(virtual-scroll): emit on viewChange inside the NgZone #12873

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 2 commits into from
Aug 29, 2018

Conversation

mmalerba
Copy link
Contributor

fixes #12869

@mmalerba mmalerba added the P2 The issue is important to a large percentage of users, with a workaround label Aug 28, 2018
@mmalerba mmalerba requested a review from jelbourn August 28, 2018 20:50
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 28, 2018
@mmalerba mmalerba added the target: major This PR is targeted for the next major release label Aug 28, 2018
@SkipSelf() private _viewport: CdkVirtualScrollViewport) {
@SkipSelf() private _viewport: CdkVirtualScrollViewport,
/** The Angular zone. */
ngZone: NgZone) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be optional with a breaking change for next major?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

virtual scroll isn't released yet so its ok

@@ -166,14 +167,16 @@ export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy
/** The set of available differs. */
private _differs: IterableDiffers,
/** The virtual scrolling viewport that these items are being rendered in. */
@SkipSelf() private _viewport: CdkVirtualScrollViewport) {
@SkipSelf() private _viewport: CdkVirtualScrollViewport,
/** The Angular zone. */
Copy link
Member

Choose a reason for hiding this comment

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

This comment doesn't contribute much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, removed

this.dataStream.subscribe(data => {
this._data = data;
this._onRenderedDataChange();
});
this._viewport.renderedRangeStream.pipe(takeUntil(this._destroyed)).subscribe(range => {
this._renderedRange = range;
this.viewChange.next(this._renderedRange);
ngZone.run(() => this.viewChange.next(this._renderedRange));
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to write a test for this. Something like:

const spy = jasmine.createSpy('something');

renderedRangeStream.subscribe(() => spy(NgZone.isInAngularZone()));

expect(spy).toHaveBeenCalledWith(true);

@mmalerba
Copy link
Contributor Author

test added

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -166,14 +167,15 @@ export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy
/** The set of available differs. */
private _differs: IterableDiffers,
/** The virtual scrolling viewport that these items are being rendered in. */
@SkipSelf() private _viewport: CdkVirtualScrollViewport) {
@SkipSelf() private _viewport: CdkVirtualScrollViewport,
ngZone: NgZone) {
Copy link
Member

Choose a reason for hiding this comment

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

I left this before, but I think it got lost between commits: shouldn't we make this an optional parameter with a breaking change for the next major?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

virtual scroll isn't released yet, so it's not necessary

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Aug 28, 2018
@ngbot
Copy link

ngbot bot commented Aug 28, 2018

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure status "ci/circleci: build" is failing
    pending status "continuous-integration/travis-ci/pr" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@jelbourn jelbourn merged commit 0d406b3 into angular:master Aug 29, 2018
@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 9, 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 P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

virtual-scroll: Change detection not triggered when using DataSource that uses viewChange.
4 participants