mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 21:35:47 +00:00
minor performance improvements
This commit is contained in:
parent
b2b170099f
commit
b288cb08b4
4 changed files with 23 additions and 16 deletions
|
|
@ -16,7 +16,7 @@ var consoleNode,
|
||||||
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
|
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
|
||||||
jqLite = jQuery || jqLiteWrap,
|
jqLite = jQuery || jqLiteWrap,
|
||||||
slice = Array.prototype.slice,
|
slice = Array.prototype.slice,
|
||||||
error = window['console'] ? bind(window['console'], window['console']['error']) : noop,
|
error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop,
|
||||||
angular = window['angular'] || (window['angular'] = {}),
|
angular = window['angular'] || (window['angular'] = {}),
|
||||||
angularTextMarkup = extensionMap(angular, 'textMarkup'),
|
angularTextMarkup = extensionMap(angular, 'textMarkup'),
|
||||||
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
||||||
|
|
@ -292,12 +292,14 @@ function escapeAttr(html) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bind(_this, _function) {
|
function bind(_this, _function) {
|
||||||
if (!isFunction(_function))
|
|
||||||
throw "Not a function!";
|
|
||||||
var curryArgs = slice.call(arguments, 2, arguments.length);
|
var curryArgs = slice.call(arguments, 2, arguments.length);
|
||||||
return function() {
|
return curryArgs.length == 0 ?
|
||||||
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
function() {
|
||||||
};
|
return _function.apply(_this, arguments);
|
||||||
|
} :
|
||||||
|
function() {
|
||||||
|
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function outerHTML(node) {
|
function outerHTML(node) {
|
||||||
|
|
@ -331,12 +333,12 @@ function merge(src, dst) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile(element, parentScope, overrides) {
|
function compile(element, parentScope) {
|
||||||
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
|
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
|
||||||
$element = jqLite(element),
|
$element = jqLite(element),
|
||||||
parent = extend({}, parentScope);
|
parent = extend({}, parentScope);
|
||||||
parent.$element = $element;
|
parent.$element = $element;
|
||||||
return compiler.compile($element)($element, parent, overrides);
|
return compiler.compile($element)($element, parent);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,9 @@ Template.prototype = {
|
||||||
element = jqLite(element);
|
element = jqLite(element);
|
||||||
foreach(this.inits, function(fn) {
|
foreach(this.inits, function(fn) {
|
||||||
queue.push(function(scope) {
|
queue.push(function(scope) {
|
||||||
scope.$tryEval(fn, element, element);
|
scope.$tryEval(function(){
|
||||||
|
return fn.call(scope, element);
|
||||||
|
}, element);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ function createScope(parent, services, existing) {
|
||||||
|
|
||||||
$eval: function $eval(exp) {
|
$eval: function $eval(exp) {
|
||||||
if (exp !== undefined) {
|
if (exp !== undefined) {
|
||||||
return expressionCompile(exp).apply(instance, slice.call(arguments, 1, arguments.length));
|
return expressionCompile(exp).call(instance);
|
||||||
} else {
|
} else {
|
||||||
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
|
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
|
||||||
for ( var queue = evalLists.sorted[i],
|
for ( var queue = evalLists.sorted[i],
|
||||||
|
|
@ -145,7 +145,7 @@ function createScope(parent, services, existing) {
|
||||||
|
|
||||||
$tryEval: function (expression, exceptionHandler) {
|
$tryEval: function (expression, exceptionHandler) {
|
||||||
try {
|
try {
|
||||||
return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length));
|
return expressionCompile(expression).call(instance);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
(instance.$log || {error:error}).error(e);
|
(instance.$log || {error:error}).error(e);
|
||||||
if (isFunction(exceptionHandler)) {
|
if (isFunction(exceptionHandler)) {
|
||||||
|
|
@ -161,12 +161,15 @@ function createScope(parent, services, existing) {
|
||||||
$watch: function(watchExp, listener, exceptionHandler) {
|
$watch: function(watchExp, listener, exceptionHandler) {
|
||||||
var watch = expressionCompile(watchExp),
|
var watch = expressionCompile(watchExp),
|
||||||
last;
|
last;
|
||||||
|
listener = expressionCompile(listener);
|
||||||
function watcher(){
|
function watcher(){
|
||||||
var value = watch.call(instance),
|
var value = watch.call(instance),
|
||||||
lastValue = last;
|
lastValue = last;
|
||||||
if (last !== value) {
|
if (last !== value) {
|
||||||
last = value;
|
last = value;
|
||||||
instance.$tryEval(listener, exceptionHandler, value, lastValue);
|
instance.$tryEval(function(){
|
||||||
|
return listener.call(instance, value, lastValue);
|
||||||
|
}, exceptionHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance.$onEval(PRIORITY_WATCH, watcher);
|
instance.$onEval(PRIORITY_WATCH, watcher);
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ describe('scope/model', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('$eval', function(){
|
describe('$eval', function(){
|
||||||
it('should eval function with correct this and pass arguments', function(){
|
it('should eval function with correct this', function(){
|
||||||
var model = createScope();
|
var model = createScope();
|
||||||
model.$eval(function(name){
|
model.$eval(function(){
|
||||||
this.name = name;
|
this.name = 'works';
|
||||||
}, 'works');
|
});
|
||||||
expect(model.name).toEqual('works');
|
expect(model.name).toEqual('works');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue