Skip to content

Commit 1f8fa3e

Browse files
authored
refactor: remove use of zone onStable in performance demo (#28661)
1 parent 7ec1e48 commit 1f8fa3e

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/dev-app/performance/performance-demo.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {AfterViewInit, Component, NgZone, ViewChild} from '@angular/core';
9+
import {
10+
afterNextRender,
11+
AfterViewInit,
12+
Component,
13+
inject,
14+
Injector,
15+
ViewChild,
16+
} from '@angular/core';
1017
import {CommonModule} from '@angular/common';
1118
import {FormsModule} from '@angular/forms';
1219

@@ -19,8 +26,6 @@ import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator';
1926
import {MatSelectModule} from '@angular/material/select';
2027
import {MatTableDataSource, MatTableModule} from '@angular/material/table';
2128

22-
import {take} from 'rxjs/operators';
23-
2429
@Component({
2530
selector: 'performance-demo',
2631
templateUrl: 'performance-demo.html',
@@ -67,6 +72,8 @@ export class PerformanceDemo implements AfterViewInit {
6772
/** Used in an `@for` to render the desired number of comonents. */
6873
componentArray = [].constructor(this.componentCount);
6974

75+
private _injector = inject(Injector);
76+
7077
/** The standard deviation of the recorded samples. */
7178
get stdev(): number | undefined {
7279
if (!this.allSamples.length) {
@@ -86,8 +93,6 @@ export class PerformanceDemo implements AfterViewInit {
8693
return this.allSamples.reduce((a, b) => a + b) / this.allSamples.length;
8794
}
8895

89-
constructor(private _ngZone: NgZone) {}
90-
9196
@ViewChild(MatPaginator) paginator?: MatPaginator;
9297

9398
ngAfterViewInit() {
@@ -131,11 +136,14 @@ export class PerformanceDemo implements AfterViewInit {
131136
setTimeout(() => {
132137
this.show = true;
133138
const start = performance.now();
134-
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
135-
const end = performance.now();
136-
this.show = false;
137-
res(end - start);
138-
});
139+
afterNextRender(
140+
() => {
141+
const end = performance.now();
142+
this.show = false;
143+
res(end - start);
144+
},
145+
{injector: this._injector},
146+
);
139147
});
140148
});
141149
}

0 commit comments

Comments
 (0)