Last active
November 30, 2022 22:30
-
-
Save christianliebel/ec9d43aa044ce87412571a714790ce2d to your computer and use it in GitHub Desktop.
Angular Performance Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'my-component', | |
template: '{{ foo }}', | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class MyComponent { | |
@Input() | |
foo: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<my-component [foo]="bar"></my-component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: string; | |
subscription: Subscription; | |
constructor(private dataService: DataService, private cdRef: ChangeDetectorRef) {} | |
ngOnInit() { | |
this.subscription = this.dataService.updates$.subscribe(data => { | |
this.data = data; | |
this.cdRef.markForCheck(); | |
}); | |
} | |
ngOnDestroy() { | |
this.subscription.unsubscribe(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data$: Observable<string>; | |
constructor(dataService: DataService) { | |
this.data$ = dataService.updates$; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ data$ | async }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
platformBrowserDynamic().bootstrapModule(AppModule) | |
.then(moduleRef => { | |
const applicationRef = moduleRef.injector.get(ApplicationRef); | |
const appComponent = applicationRef.components[0]; | |
enableDebugTools(appComponent); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div (click)="foo()"> | |
<button (click)="bar()">Test</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
platformBrowserDynamic() | |
.bootstrapModule(AppModule, { ngZoneEventCoalescing: true }) | |
.catch(err => console.error(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(ngZone: NgZone) { | |
ngZone.runOutsideAngular(() => { | |
// runs outside Angular zone, for performance-critical code | |
ngZone.run(() => { | |
// runs inside Angular zone, for updating view afterwards | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(window as any).__Zone_disable_requestAnimationFrame = true; | |
// disable patch requestAnimationFrame | |
(window as any).__Zone_disable_on_property = true; | |
// disable patch onProperty such as onclick | |
(window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; | |
// disable patch specified eventNames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(applicationRef: ApplicationRef) { | |
applicationRef.tick(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
platformBrowserDynamic().bootstrapModule(AppModule, { | |
ngZone: 'noop' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment