Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9bdb214

Browse files
committed
WIP: use one locals object
1 parent 9b4e0c9 commit 9bdb214

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/ng/directive/select.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
345345
// We try to reuse these if possible
346346
// - optionGroupsCache[0] is the options with no option group
347347
// - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
348-
optionGroupsCache = [[{element: selectElement, label:''}]];
348+
optionGroupsCache = [[{element: selectElement, label:''}]],
349+
//re-usable object to represent option's locals
350+
locals = {};
349351

350352
if (nullOption) {
351353
// compile the element since there might be bindings in it
@@ -367,7 +369,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
367369
scope.$apply(function() {
368370
var optionGroup,
369371
collection = valuesFn(scope) || [],
370-
locals = {},
371372
key, value, optionElement, index, groupIndex, length, groupLength, trackIndex;
372373
var selectedKeys = selectElement.val();
373374
var viewValue;
@@ -388,8 +389,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
388389

389390
scope.$watchCollection(valuesFn, scheduleRendering);
390391
scope.$watchCollection(function () {
391-
var locals = {},
392-
values = valuesFn(scope);
392+
var values = valuesFn(scope);
393393
if (values) {
394394
var toDisplay = new Array(values.length);
395395
for (var i = 0, ii = values.length; i < ii; i++) {
@@ -411,7 +411,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
411411
var viewValue = ctrl.$viewValue;
412412
if (trackFn && isArray(viewValue) && !selectAs) {
413413
selectedSet = new HashMap([]);
414-
var locals = {};
415414
for (var trackIndex = 0; trackIndex < viewValue.length; trackIndex++) {
416415
locals[valueName] = viewValue[trackIndex];
417416
selectedSet.put(trackFn(scope, locals), viewValue[trackIndex]);
@@ -436,8 +435,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
436435

437436
// TODO: Use this method everywhere
438437
function callExpression(exprFn, key, collection) {
439-
// TODO: keep this as a central object, no need to recreate this
440-
var locals = {};
441438
locals[valueName] = collection[key];
442439
if (keyName) locals[keyName] = key;
443440
return exprFn(scope, locals);
@@ -489,7 +486,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
489486
key,
490487
groupLength, length,
491488
groupIndex, index,
492-
locals = {},
493489
selected,
494490
selectedSet = getSelectedSet(),
495491
lastElement,
@@ -502,10 +498,10 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
502498
if (keyName) {
503499
key = keys[index];
504500
if ( key.charAt(0) === '$' ) continue;
505-
locals[keyName] = key;
506501
}
507502

508-
locals[valueName] = values[key];
503+
//Called without assigning value to reset properties of locals object
504+
var optionValue = callExpression(noop, key, values);
509505

510506
optionGroupName = groupByFn(scope, locals) || '';
511507
if (!(optionGroup = optionGroups[optionGroupName])) {

0 commit comments

Comments
 (0)