From dbeecc2caa5891ce041fcfec56ce9a7b67e08d49 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 28 Feb 2024 21:10:43 +0000 Subject: [PATCH] refactor: remove use of zone onStable in performance demo --- src/dev-app/performance/performance-demo.ts | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/dev-app/performance/performance-demo.ts b/src/dev-app/performance/performance-demo.ts index a066adcee10a..1bc1d5b8bec7 100644 --- a/src/dev-app/performance/performance-demo.ts +++ b/src/dev-app/performance/performance-demo.ts @@ -6,7 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {AfterViewInit, Component, NgZone, ViewChild} from '@angular/core'; +import { + afterNextRender, + AfterViewInit, + Component, + inject, + Injector, + ViewChild, +} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; @@ -19,8 +26,6 @@ import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator'; import {MatSelectModule} from '@angular/material/select'; import {MatTableDataSource, MatTableModule} from '@angular/material/table'; -import {take} from 'rxjs/operators'; - @Component({ selector: 'performance-demo', templateUrl: 'performance-demo.html', @@ -67,6 +72,8 @@ export class PerformanceDemo implements AfterViewInit { /** Used in an `@for` to render the desired number of comonents. */ componentArray = [].constructor(this.componentCount); + private _injector = inject(Injector); + /** The standard deviation of the recorded samples. */ get stdev(): number | undefined { if (!this.allSamples.length) { @@ -86,8 +93,6 @@ export class PerformanceDemo implements AfterViewInit { return this.allSamples.reduce((a, b) => a + b) / this.allSamples.length; } - constructor(private _ngZone: NgZone) {} - @ViewChild(MatPaginator) paginator?: MatPaginator; ngAfterViewInit() { @@ -131,11 +136,14 @@ export class PerformanceDemo implements AfterViewInit { setTimeout(() => { this.show = true; const start = performance.now(); - this._ngZone.onStable.pipe(take(1)).subscribe(() => { - const end = performance.now(); - this.show = false; - res(end - start); - }); + afterNextRender( + () => { + const end = performance.now(); + this.show = false; + res(end - start); + }, + {injector: this._injector}, + ); }); }); }