Value checking in ngModel length watch? #288
Description
I'm using ui-sortable in a web app that can contain a very large number of elements to sort. I've noticed that initial load can be extremely long, especially in Firefox where the "Unresponsive Script Warning" ends up showing up between 3 and 4 times before everything is finalized. I understand this is a bit of an extreme case. However, I noticed that if I make a very small adjustment to the attrs.ngModel+'.length'
watch, everything loads faster.
Before:
72 // When we add or remove elements, we need the sortable to 'refresh'
73 // so it can find the new/removed elements.
74 scope.$watch(attrs.ngModel+'.length', function() {
75 // Timeout to let ng-repeat modify the DOM
76 $timeout(function() {
77 // ensure that the jquery-ui-sortable widget instance
78 // is still bound to the directive's element
79 if (!!element.data('ui-sortable')) {
80 element.sortable('refresh');
81 }
82 });
83 });
After
72 // When we add or remove elements, we need the sortable to 'refresh'
73 // so it can find the new/removed elements.
74 scope.$watch(attrs.ngModel+'.length', function(newVal, oldVal) {
75 if (newVal === oldVal) {
76 return;
77 }
78 // Timeout to let ng-repeat modify the DOM
79 $timeout(function() {
80 // ensure that the jquery-ui-sortable widget instance
81 // is still bound to the directive's element
82 if (!!element.data('ui-sortable')) {
83 element.sortable('refresh');
84 }
85 });
86 });
As you can see, the only thing I changed was adding newVal/oldVal parameters and checking to make sure something changed before doing anything else.
The main reason why I don't have this as a Pull Request is I'm fairly ignorant as to what the consequences of this change, if any, are. So far, everything tied to drag and drop seems to perform just fine, so I think it's worth adding.