The equality comparator watcher can be a fickle beast when tuning the application for better performance. It's always best to avoid it when possible, but of course, that holds true until you actually need to deep watch a collection of large objects. The overhead of watching a large object is so cumbersome that sometimes distilling objects down to a subset for the purposes of comparison can actually yield performance gains.
The following is the naïve method of an exhaustive equality comparator watch:
$scope.$watch('bigObjectArray', function() { // watch callback }, true);
Instead of watching the entire object, it is possible to call map()
on a collection of large objects in order to extract only the components of the objects that actually need to be watched. This can be done as follows:
$scope.$watch( // function that returns object to be watched function($scope) { // map the array to distill the relevant properties // this return value...