Skip to content

Commit

Permalink
Revert "perf(cdk/scrolling): do not run change detection if there are…
Browse files Browse the repository at this point in the history
… no `viewChange` listeners (angular#23987)"

This reverts commit ad33d7a.
  • Loading branch information
wagnermaciel authored and forsti0506 committed Apr 3, 2022
1 parent 9137f42 commit f04183c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
4 changes: 1 addition & 3 deletions src/cdk/scrolling/virtual-for-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ export class CdkVirtualForOf<T>
});
this._viewport.renderedRangeStream.pipe(takeUntil(this._destroyed)).subscribe(range => {
this._renderedRange = range;
if (this.viewChange.observers.length) {
ngZone.run(() => this.viewChange.next(this._renderedRange));
}
ngZone.run(() => this.viewChange.next(this._renderedRange));
this._onRenderedDataChange();
});
this._viewport.attach(this);
Expand Down
38 changes: 0 additions & 38 deletions src/cdk/scrolling/virtual-scroll-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ViewEncapsulation,
Directive,
ViewContainerRef,
ApplicationRef,
} from '@angular/core';
import {
waitForAsync,
Expand Down Expand Up @@ -787,43 +786,6 @@ describe('CdkVirtualScrollViewport', () => {
}
}).not.toThrow();
}));

describe('viewChange change detection behavior', () => {
let appRef: ApplicationRef;

beforeEach(inject([ApplicationRef], (ar: ApplicationRef) => {
appRef = ar;
}));

it('should not run change detection if there are no viewChange listeners', fakeAsync(() => {
finishInit(fixture);
testComponent.items = Array(10).fill(0);
fixture.detectChanges();
flush();

spyOn(appRef, 'tick');

viewport.scrollToIndex(5);
triggerScroll(viewport);

expect(appRef.tick).not.toHaveBeenCalled();
}));

it('should run change detection if there are any viewChange listeners', fakeAsync(() => {
testComponent.virtualForOf.viewChange.subscribe();
finishInit(fixture);
testComponent.items = Array(10).fill(0);
fixture.detectChanges();
flush();

spyOn(appRef, 'tick');

viewport.scrollToIndex(5);
triggerScroll(viewport);

expect(appRef.tick).toHaveBeenCalledTimes(1);
}));
});
});

describe('with RTL direction', () => {
Expand Down

0 comments on commit f04183c

Please sign in to comment.