Peter Malina
FlowUp Academy Trainings
Model
DOM
// very simplified version of actual source
class ApplicationRef {
changeDetectorRefs:ChangeDetectorRef[] = [];
constructor(private zone: NgZone) {
this.zone.onTurnDone
.subscribe(() => this.zone.run(() => this.tick());
}
tick() {
this.changeDetectorRefs
.forEach((ref) => ref.detectChanges());
}
}Change
Change
@Component({
template: `{{data}}`,
changeDetection: ChangeDetectionStrategy.OnPush
})
class MyComponent {
@Input() data;
}var peter = Immutable.map({
name: 'Peter'
});
var arbelt = peter.set('name', 'Arbelt');
peter === arbelt // false@Component({
template: '{{counter}}',
changeDetection: ChangeDetectionStrategy.OnPush
})
class CounterComponent {
@Input() counterStream: Observable<any>;
counter = 0;
ngOnInit() {
this.counterStream.subscribe(() => {
this.counter++;
})
}
}@Component({
template: '{{counter}}',
changeDetection: ChangeDetectionStrategy.OnPush
})
class CounterComponent {
@Input() counterStream: Observable<any>;
counter = 0;
constructor(private cd: ChangeDetectorRef) {}
ngOnInit() {
this.counterStream.subscribe(() => {
this.counter++;
this.cd.markForCheck();
})
}
}