I've always believed that slice
is pure and it's sole advantage over calling slice
method on string or array is caching mechanism of pure pipes in Angular.
Turns out it isn't the case and slice
is impure. Moreover implementation is very basic: it guards against null
s and delegates to slice
method. No internal comparison of last transformed input.
I suspect it is designed to align with behavior of ngFor
, but is it a viable reason? Newcomers would complain that Angular is broken otherwise I suppose, but then again why should I use this pipe?
Am I correct that it creates new arrays in every change detection run, which leads to triggering even OnPush
change detection down the three and nullifying performance optimizations?
Edit: This question is based on assumption that one should use immutable data.