Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/dev-app/performance/performance-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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},
);
});
});
}
Expand Down