refactor($rootScope): consistently use noop as the default $watch listener
Closes #16343
This commit is contained in:
committed by
Martin Staffa
parent
da72477701
commit
394b185416
@@ -331,9 +331,7 @@ function $InterpolateProvider() {
|
||||
var lastValue;
|
||||
return scope.$watchGroup(parseFns, /** @this */ function interpolateFnWatcher(values, oldValues) {
|
||||
var currValue = compute(values);
|
||||
if (isFunction(listener)) {
|
||||
listener.call(this, currValue, values !== oldValues ? lastValue : currValue, scope);
|
||||
}
|
||||
listener.call(this, currValue, values !== oldValues ? lastValue : currValue, scope);
|
||||
lastValue = currValue;
|
||||
});
|
||||
}
|
||||
|
||||
+3
-6
@@ -394,14 +394,15 @@ function $RootScopeProvider() {
|
||||
*/
|
||||
$watch: function(watchExp, listener, objectEquality, prettyPrintExpression) {
|
||||
var get = $parse(watchExp);
|
||||
var fn = isFunction(listener) ? listener : noop;
|
||||
|
||||
if (get.$$watchDelegate) {
|
||||
return get.$$watchDelegate(this, listener, objectEquality, get, watchExp);
|
||||
return get.$$watchDelegate(this, fn, objectEquality, get, watchExp);
|
||||
}
|
||||
var scope = this,
|
||||
array = scope.$$watchers,
|
||||
watcher = {
|
||||
fn: listener,
|
||||
fn: fn,
|
||||
last: initWatchVal,
|
||||
get: get,
|
||||
exp: prettyPrintExpression || watchExp,
|
||||
@@ -410,10 +411,6 @@ function $RootScopeProvider() {
|
||||
|
||||
lastDirtyWatch = null;
|
||||
|
||||
if (!isFunction(listener)) {
|
||||
watcher.fn = noop;
|
||||
}
|
||||
|
||||
if (!array) {
|
||||
array = scope.$$watchers = [];
|
||||
array.$$digestWatchIndex = -1;
|
||||
|
||||
@@ -34,7 +34,7 @@ function parseTextLiteral(text) {
|
||||
parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) {
|
||||
var unwatch = scope['$watch'](noop,
|
||||
function textLiteralWatcher() {
|
||||
if (isFunction(listener)) { listener(text, text, scope); }
|
||||
listener(text, text, scope);
|
||||
unwatch();
|
||||
},
|
||||
objectEquality);
|
||||
@@ -58,7 +58,7 @@ function subtractOffset(expressionFn, offset) {
|
||||
parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) {
|
||||
unwatch = scope['$watch'](expressionFn,
|
||||
function pluralExpressionWatchListener(newValue, oldValue) {
|
||||
if (isFunction(listener)) { listener(minusOffset(newValue), minusOffset(oldValue), scope); }
|
||||
listener(minusOffset(newValue), minusOffset(oldValue), scope);
|
||||
},
|
||||
objectEquality);
|
||||
return unwatch;
|
||||
|
||||
@@ -122,9 +122,7 @@ function InterpolationPartsWatcher(interpolationParts, scope, listener, objectEq
|
||||
|
||||
InterpolationPartsWatcher.prototype.watchListener = function watchListener(newExpressionValues, oldExpressionValues) {
|
||||
var result = this.interpolationParts.getResult(newExpressionValues);
|
||||
if (isFunction(this.listener)) {
|
||||
this.listener.call(null, result, newExpressionValues === oldExpressionValues ? result : this.previousResult, this.scope);
|
||||
}
|
||||
this.listener.call(null, result, newExpressionValues === oldExpressionValues ? result : this.previousResult, this.scope);
|
||||
this.previousResult = result;
|
||||
};
|
||||
|
||||
|
||||
@@ -66,9 +66,7 @@ MessageSelectorWatchers.prototype.expressionFnListener = function expressionFnLi
|
||||
};
|
||||
|
||||
MessageSelectorWatchers.prototype.messageFnListener = function messageFnListener(newMessage, oldMessage) {
|
||||
if (isFunction(this.listener)) {
|
||||
this.listener.call(null, newMessage, newMessage === oldMessage ? newMessage : this.lastMessage, this.scope);
|
||||
}
|
||||
this.listener.call(null, newMessage, newMessage === oldMessage ? newMessage : this.lastMessage, this.scope);
|
||||
this.lastMessage = newMessage;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user