Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor($rootScope): consistently use noop as the default $watch listener #16343

Merged
merged 1 commit into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/ng/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
9 changes: 3 additions & 6 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -410,10 +411,6 @@ function $RootScopeProvider() {

lastDirtyWatch = null;

if (!isFunction(listener)) {
watcher.fn = noop;
}

if (!array) {
array = scope.$$watchers = [];
array.$$digestWatchIndex = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/ngMessageFormat/messageFormatCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/ngMessageFormat/messageFormatInterpolationParts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 1 addition & 3 deletions src/ngMessageFormat/messageFormatSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down