Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
perf(options): use while loop instead of forEach to iterate over options
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Burgmer committed Jul 21, 2014
1 parent 43d1b5a commit bd6c441
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/w11k-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ angular.module('w11k.select').directive('w11kSelect', [
});

if (selectedOptions.length > 0) {
scope.deselectAll();
setSelected(selectedOptions, false);
selectedOptions[0].selected = true;
}
}
Expand Down Expand Up @@ -418,9 +418,7 @@ angular.module('w11k.select').directive('w11kSelect', [
}

if (scope.config.multiple) {
angular.forEach(optionsFiltered, function (option) {
option.selected = true;
});
setSelected(optionsFiltered, true);
}
else if (optionsFiltered.length === 1) {
optionsFiltered[0].selected = true;
Expand All @@ -435,10 +433,7 @@ angular.module('w11k.select').directive('w11kSelect', [
$event.stopPropagation();
}

angular.forEach(optionsFiltered, function (option) {
option.selected = false;
});

setSelected(optionsFiltered, false);
setViewValue();
};

Expand All @@ -448,10 +443,7 @@ angular.module('w11k.select').directive('w11kSelect', [
$event.stopPropagation();
}

angular.forEach(options, function (option) {
option.selected = false;
});

setSelected(options, false);
setViewValue();
};

Expand Down Expand Up @@ -501,8 +493,9 @@ angular.module('w11k.select').directive('w11kSelect', [

scope.select = function (option) {
if (option.selected === false && scope.config.multiple === false) {
scope.deselectAll();
setSelected(options, false);
option.selected = true;

scope.dropdown.close();
setViewValue();
}
Expand Down Expand Up @@ -662,6 +655,13 @@ angular.module('w11k.select').directive('w11kSelect', [
* helper functions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function setSelected(options, selected) {
var i = options.length;
while (i--) {
options[i].selected = selected;
}
}

function options2model(options) {
var selectedOptions = options.filter(function (option) {
return option.selected;
Expand Down

0 comments on commit bd6c441

Please sign in to comment.