mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +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)),
|
||||
jqLite = jQuery || jqLiteWrap,
|
||||
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'] = {}),
|
||||
angularTextMarkup = extensionMap(angular, 'textMarkup'),
|
||||
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
||||
|
|
@ -292,12 +292,14 @@ function escapeAttr(html) {
|
|||
}
|
||||
|
||||
function bind(_this, _function) {
|
||||
if (!isFunction(_function))
|
||||
throw "Not a function!";
|
||||
var curryArgs = slice.call(arguments, 2, arguments.length);
|
||||
return function() {
|
||||
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
||||
};
|
||||
return curryArgs.length == 0 ?
|
||||
function() {
|
||||
return _function.apply(_this, arguments);
|
||||
} :
|
||||
function() {
|
||||
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
||||
};
|
||||
}
|
||||
|
||||
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),
|
||||
$element = jqLite(element),
|
||||
parent = extend({}, parentScope);
|
||||
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);
|
||||
foreach(this.inits, function(fn) {
|
||||
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) {
|
||||
if (exp !== undefined) {
|
||||
return expressionCompile(exp).apply(instance, slice.call(arguments, 1, arguments.length));
|
||||
return expressionCompile(exp).call(instance);
|
||||
} else {
|
||||
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
|
||||
for ( var queue = evalLists.sorted[i],
|
||||
|
|
@ -145,7 +145,7 @@ function createScope(parent, services, existing) {
|
|||
|
||||
$tryEval: function (expression, exceptionHandler) {
|
||||
try {
|
||||
return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length));
|
||||
return expressionCompile(expression).call(instance);
|
||||
} catch (e) {
|
||||
(instance.$log || {error:error}).error(e);
|
||||
if (isFunction(exceptionHandler)) {
|
||||
|
|
@ -161,12 +161,15 @@ function createScope(parent, services, existing) {
|
|||
$watch: function(watchExp, listener, exceptionHandler) {
|
||||
var watch = expressionCompile(watchExp),
|
||||
last;
|
||||
listener = expressionCompile(listener);
|
||||
function watcher(){
|
||||
var value = watch.call(instance),
|
||||
lastValue = last;
|
||||
if (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);
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ describe('scope/model', 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();
|
||||
model.$eval(function(name){
|
||||
this.name = name;
|
||||
}, 'works');
|
||||
model.$eval(function(){
|
||||
this.name = 'works';
|
||||
});
|
||||
expect(model.name).toEqual('works');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue