From 48ee70ed9ace4fb61026f5032a7849596b65e599 Mon Sep 17 00:00:00 2001 From: Dan Schuman Date: Thu, 7 Aug 2014 14:38:38 -0700 Subject: [PATCH 1/2] Performance: Adjust $watch statement so it does not run every $digest --- src/nya-bootstrap-select.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nya-bootstrap-select.js b/src/nya-bootstrap-select.js index 26b9705..ac24ab2 100644 --- a/src/nya-bootstrap-select.js +++ b/src/nya-bootstrap-select.js @@ -78,7 +78,7 @@ angular.module('nya.bootstrap.select',[]) } }; - scope.$watch(function optionDOMWatch(){ + function optionDOMWatch(){ // check every option if has changed. var optionElements = $(element).find('option'); @@ -112,8 +112,17 @@ 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') ) + }; + // If any of the above properties change, call optionDOMWatch. + }, optionDOMWatch, true); var setValue = function(modelValue) { var collection = valuesFn(scope); From 15d5465096d981a901213192f149ce4437adb96b Mon Sep 17 00:00:00 2001 From: Dan Schuman Date: Thu, 7 Aug 2014 14:58:25 -0700 Subject: [PATCH 2/2] Performance: Adjust $watch statement so it does not run every $digest --- src/nya-bootstrap-select.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nya-bootstrap-select.js b/src/nya-bootstrap-select.js index ac24ab2..76f66b4 100644 --- a/src/nya-bootstrap-select.js +++ b/src/nya-bootstrap-select.js @@ -46,6 +46,8 @@ angular.module('nya.bootstrap.select',[]) angular.forEach(BS_ATTR, function(attr) { selectorOptions[attr] = attrs[attr]; }); + + return selectorOptions; }; /** @@ -119,7 +121,8 @@ angular.module('nya.bootstrap.select',[]) // This is slow, but not as slow as calling optionDOMWatch every $digest return { ngModel: ngCtrl.$viewValue, - options: makeOptionArray( $(element).find('option') ) + options: makeOptionArray( $(element).find('option') ), + selectors: updateSelectorOptions() }; // If any of the above properties change, call optionDOMWatch. }, optionDOMWatch, true);