diff options
| author | Shyam Seshadri | 2010-06-02 15:04:26 -0700 | 
|---|---|---|
| committer | Shyam Seshadri | 2010-06-02 15:04:26 -0700 | 
| commit | a29c5e4c7fd5e708c28e70e974bf873621d5277c (patch) | |
| tree | 17efcdc2df48d32a0a928cc2ab755f355e9f6ae1 /src/directives.js | |
| parent | 6143b04384680d17f38c2d5894a9b9961ea33288 (diff) | |
| download | angular.js-a29c5e4c7fd5e708c28e70e974bf873621d5277c.tar.bz2 | |
Revert "removed few key foreach and replaced thime with for loop for performance."
This reverts commit 6143b04384680d17f38c2d5894a9b9961ea33288.
Diffstat (limited to 'src/directives.js')
| -rw-r--r-- | src/directives.js | 51 | 
1 files changed, 21 insertions, 30 deletions
diff --git a/src/directives.js b/src/directives.js index cabf0c23..91a98735 100644 --- a/src/directives.js +++ b/src/directives.js @@ -24,17 +24,14 @@ angularDirective("ng-eval", function(expression){  angularDirective("ng-bind", function(expression){    return function(element) { -    var lastValue = noop, lastError = noop; +    var lastValue, lastError;      this.$onEval(function() {        var error,            value = this.$tryEval(expression, function(e){              error = toJson(e);            }), -          isHtml, -          isDomElement; -      if (lastValue === value && lastError == error) return; -      isHtml = value instanceof HTML, -      isDomElement = isElement(value); +          isHtml = value instanceof HTML, +          isDomElement = isElement(value);        if (!isHtml && !isDomElement && isObject(value)) {          value = toJson(value);        } @@ -75,14 +72,14 @@ function compileBindTemplate(template){      });      bindTemplateCache[template] = fn = function(element){        var parts = [], self = this; -      for ( var i = 0; i < bindings.length; i++) { -        var value = bindings[i].call(self, element); +      foreach(bindings, function(fn){ +        var value = fn.call(self, element);          if (isElement(value))            value = '';          else if (isObject(value))            value = toJson(value, true);          parts.push(value); -      }; +      });        return parts.join('');      };    } @@ -110,26 +107,21 @@ var REMOVE_ATTRIBUTES = {  };  angularDirective("ng-bind-attr", function(expression){    return function(element){ -    var lastValue = {};      this.$onEval(function(){ -      var values = this.$eval(expression); -      for(var key in values) { -        var value = compileBindTemplate(values[key]).call(this, element), +      foreach(this.$eval(expression), function(bindExp, key) { +        var value = compileBindTemplate(bindExp).call(this, element),              specialName = REMOVE_ATTRIBUTES[lowercase(key)]; -        if (lastValue[key] !== value) { -          lastValue[key] = value; -          if (specialName) { -            if (element[specialName] = toBoolean(value)) { -              element.attr(specialName, value); -            } else { -              element.removeAttr(key); -            } -            (element.data('$validate')||noop)(); +        if (specialName) { +          if (element[specialName] = toBoolean(value)) { +            element.attr(specialName, value);            } else { -            element.attr(key, value); +            element.removeAttr(key);            } +          (element.data('$validate')||noop)(); +        } else { +          element.attr(key, value);          } -      }; +      }, this);      }, element);    };  }); @@ -161,18 +153,17 @@ angularWidget("@ng-repeat", function(expression, element){      var children = [], currentScope = this;      this.$onEval(function(){ -      var index = 0, childCount = children.length, childScope, lastElement = reference, -          collection = this.$tryEval(rhs, reference); -      for ( var key in collection) { +      var index = 0, childCount = children.length, childScope, lastElement = reference; +      foreach(this.$tryEval(rhs, reference), function(value, key){          if (index < childCount) {            // reuse existing child            childScope = children[index]; -          childScope[valueIdent] = collection[key]; +          childScope[valueIdent] = value;            if (keyIdent) childScope[keyIdent] = key;          } else {            // grow children            childScope = template(element.clone(), createScope(currentScope)); -          childScope[valueIdent] = collection[key]; +          childScope[valueIdent] = value;            if (keyIdent) childScope[keyIdent] = key;            lastElement.after(childScope.$element);            childScope.$index = index; @@ -183,7 +174,7 @@ angularWidget("@ng-repeat", function(expression, element){          childScope.$eval();          lastElement = childScope.$element;          index ++; -      }; +      });        // shrink children        while(children.length > index) {          children.pop().$element.remove();  | 
