1
votes

I develop an Angular 2 app with ngrx and I was interested by OnPush change detection to get better performance. I read several articles about it which said : "If a component depends only on its input properties, and they are immutable, then this component can change if and only if one of its input properties changes.". Therefore, I have two (simple) questions about OnPush :

1) If my component has a mix of @Input() properties and not input properties, Is OnPush useless ?

2) Same question for a component which has only properties (no @Input).

Thanks by advance :)

1

1 Answers

1
votes

OnPush does not affect components internal state.

If you look at this excellent post by Victor Savkin, he specifically mentions

It is worth noting that a component can still have private mutable state as long as it changes only due to inputs being updated or an event being fired from within the component’s template. The only thing the OnPush strategy disallows is depending on shared mutable state. Read more about it here.

It worth spending time on this post as well as the companion post he refers to.