Skip to content

Commit

Permalink
Merge pull request #12 from Extensis/master
Browse files Browse the repository at this point in the history
Performance: Adjust $watch statement so it does not run every $digest
  • Loading branch information
lordfriend committed Aug 8, 2014
2 parents deb91e2 + 15d5465 commit 82ce67c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/nya-bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ angular.module('nya.bootstrap.select',[])
angular.forEach(BS_ATTR, function(attr) {
selectorOptions[attr] = attrs[attr];
});

return selectorOptions;
};

/**
Expand Down Expand Up @@ -78,7 +80,7 @@ angular.module('nya.bootstrap.select',[])
}
};

scope.$watch(function optionDOMWatch(){
function optionDOMWatch(){
// check every option if has changed.
var optionElements = $(element).find('option');

Expand Down Expand Up @@ -112,8 +114,18 @@ angular.module('nya.bootstrap.select',[])
}
optionArray = makeOptionArray(optionElements);
}
}

});
scope.$watch(function(){
// Create an object to deep inspect if anything has changed.
// This is slow, but not as slow as calling optionDOMWatch every $digest
return {
ngModel: ngCtrl.$viewValue,
options: makeOptionArray( $(element).find('option') ),
selectors: updateSelectorOptions()
};
// If any of the above properties change, call optionDOMWatch.
}, optionDOMWatch, true);

var setValue = function(modelValue) {
var collection = valuesFn(scope);
Expand Down

0 comments on commit 82ce67c

Please sign in to comment.