Reputation: 46900
Suppose we have a counter component like the one below that knows how to mutate its state and could have a button that triggers the increment()
function, etc.
@Component({...})
export class CounterComponent {
@Input()
count: number = 0;
increment() {
this.count++;
}
decrement() {
this.count--;
}
}
Does that disqualify it from an OnPush
notification strategy? In other words must components that qualify for OnPush
not mutate their own state.
Upvotes: 0
Views: 61
Reputation: 2146
Since counter is number but not object its value will be just copied to child component. So changing it inside will not affect changeDetection mechanism. Bacuse onpush trategy start change detection only on input value changes from parent perspective. So if you want view reflection when you change counter inside the component - use default change strategy.
Upvotes: 1