Skip to content

Instantly share code, notes, and snippets.

@christianliebel
Last active November 30, 2022 22:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianliebel/ec9d43aa044ce87412571a714790ce2d to your computer and use it in GitHub Desktop.
Save christianliebel/ec9d43aa044ce87412571a714790ce2d to your computer and use it in GitHub Desktop.
Angular Performance Article
@Component({
selector: 'my-component',
template: '{{ foo }}',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent {
@Input()
foo: string;
}
<my-component [foo]="bar"></my-component>
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();
}
data$: Observable<string>;
constructor(dataService: DataService) {
this.data$ = dataService.updates$;
}
{{ data$ | async }}
platformBrowserDynamic().bootstrapModule(AppModule)
.then(moduleRef => {
const applicationRef = moduleRef.injector.get(ApplicationRef);
const appComponent = applicationRef.components[0];
enableDebugTools(appComponent);
})
<div (click)="foo()">
<button (click)="bar()">Test</button>
</div>
platformBrowserDynamic()
.bootstrapModule(AppModule, { ngZoneEventCoalescing: true })
.catch(err => console.error(err));
constructor(ngZone: NgZone) {
ngZone.runOutsideAngular(() => {
// runs outside Angular zone, for performance-critical code
ngZone.run(() => {
// runs inside Angular zone, for updating view afterwards
});
});
}
(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
constructor(applicationRef: ApplicationRef) {
applicationRef.tick();
}
platformBrowserDynamic().bootstrapModule(AppModule, {
ngZone: 'noop'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment