Wojciech Trawiński
YouGov Front-end meeting, 2021
NgZone
Default strategy
NgZone
Default strategy
OnPush strategy
NgZone
Default strategy
OnPush strategy
NgZone
Asynchronous events
mutable update pattern
interface User {
name: string;
age: number;
}
...
public user: User = { name: "Max", age: 30 };
...
public changeUserAge(age: number): void {
this.user.age = age;
}
mutable update pattern
immutable update pattern
interface User {
name: string;
age: number;
}
...
public user: User = { name: "Max", age: 30 };
...
public changeUserAge(age: number): void {
this.user.age = age;
}
interface User {
name: string;
age: number;
}
...
public user: User = { name: "Max", age: 30 };
...
public changeUserAge(age: number): void {
this.user = { ...this.user, age };
}
timers
public date: string = null;
private dateInterval = null;
...
public showDate(): void {
this.dateInterval = setInterval(() => {
this.date = new Date().toISOString();
}, 1000);
}
timers
XHR
public date: string = null;
private dateInterval = null;
...
public showDate(): void {
this.dateInterval = setInterval(() => {
this.date = new Date().toISOString();
}, 1000);
}
public remoteData: string = null;
...
public loadData(): void {
mockResponse$.subscribe(res => {
this.remoteData = res;
});
}
export function select<T, Props, K>(
pathOrMapFn: ((state: T, props?: Props) => any) | string,
propsOrPath?: Props | string,
...paths: string[]
) {
return function selectOperator(source$: Observable<T>): Observable<K> {
let mapped$: Observable<any>;
...
return mapped$.pipe(distinctUntilChanged());
};
}
with NgRx selectors
{
...
"schematics": {
"@schematics/angular:component": {
"changeDetection": "OnPush"
}
},
...
}
angular.json