perf(scope): re-enable statement cacheing

This commit is contained in:
Misko Hevery 2011-08-12 08:57:21 -07:00
parent 42062dab34
commit 13e7df68a6
3 changed files with 12 additions and 13 deletions

View file

@ -433,7 +433,7 @@ Scope.prototype = {
*/ */
$eval: function(expr) { $eval: function(expr) {
var fn = isString(expr) var fn = isString(expr)
? parser(expr).statements() ? expressionCompile(expr)
: expr || noop; : expr || noop;
return fn(this); return fn(this);
}, },
@ -495,7 +495,7 @@ Scope.prototype = {
function compileToFn(exp, name) { function compileToFn(exp, name) {
var fn = isString(exp) var fn = isString(exp)
? parser(exp).statements() ? expressionCompile(exp)
: exp; : exp;
assertArgFn(fn, name); assertArgFn(fn, name);
return fn; return fn;

View file

@ -205,6 +205,7 @@ angularDirective("ng:controller", function(expression){
*/ */
angularDirective("ng:bind", function(expression, element){ angularDirective("ng:bind", function(expression, element){
element.addClass('ng-binding'); element.addClass('ng-binding');
var exprFn = parser(expression).statements();
return function(element) { return function(element) {
var lastValue = noop, lastError = noop; var lastValue = noop, lastError = noop;
this.$watch(function(scope) { this.$watch(function(scope) {
@ -215,7 +216,7 @@ angularDirective("ng:bind", function(expression, element){
// TODO(misko): get rid of $element https://github.com/angular/angular.js/issues/348 // TODO(misko): get rid of $element https://github.com/angular/angular.js/issues/348
scope.$element = element; scope.$element = element;
try { try {
value = scope.$eval(expression); value = exprFn(scope);
} catch (e) { } catch (e) {
scope.$service('$exceptionHandler')(e); scope.$service('$exceptionHandler')(e);
error = formatError(e); error = formatError(e);

View file

@ -526,23 +526,21 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn, textBox) {
var scope = this, var scope = this,
model = modelAccessor(scope, element), model = modelAccessor(scope, element),
view = viewAccessor(scope, element), view = viewAccessor(scope, element),
action = element.attr('ng:change') || noop, ngChange = element.attr('ng:change') || noop,
lastValue; lastValue;
if (model) { if (model) {
initFn.call(scope, model, view, element); initFn.call(scope, model, view, element);
scope.$eval(element.attr('ng:init') || noop); scope.$eval(element.attr('ng:init') || noop);
element.bind(events, function(event){ element.bind(events, function(event){
function handler(){ function handler(){
scope.$apply(function() { var value = view.get();
var value = view.get(); if (!textBox || value != lastValue) {
if (!textBox || value != lastValue) { model.set(value);
model.set(value); lastValue = model.get();
lastValue = model.get(); scope.$eval(ngChange);
scope.$eval(action); }
}
});
} }
event.type == 'keydown' ? $defer(handler) : handler(); event.type == 'keydown' ? $defer(handler) : scope.$apply(handler);
}); });
scope.$watch(model.get, function(scope, value) { scope.$watch(model.get, function(scope, value) {
if (!equals(lastValue, value)) { if (!equals(lastValue, value)) {