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

Commit

Permalink
fix(*): name all anonymous watch functions in Angular
Browse files Browse the repository at this point in the history
This will allow us to see function names in Batarang and debugger.

Closes #1119
  • Loading branch information
shyamseshadri authored and mhevery committed Sep 11, 2012
1 parent f7a8f17 commit 2c6aa4c
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ docsApp.controller.DocsController = function($scope, $location, $window, $cookie
tutorial: 'Tutorial',
cookbook: 'Examples'
};
$scope.$watch(function() {return $location.path(); }, function(path) {
$scope.$watch(function docsPathWatch() {return $location.path(); }, function docsPathWatchAction(path) {
// ignore non-doc links which are used in examples
if (DOCS_PATH.test(path)) {
var parts = path.split('/'),
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap-prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
}, $delegate);
}]);
$provide.decorator('$rootScope', ['$delegate', function(embedRootScope) {
docsRootScope.$watch(function() {
docsRootScope.$watch(function embedRootScopeDigestWatch() {
embedRootScope.$digest();
});
return embedRootScope;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ directive.dropdownToggle =
return {
restrict: 'C',
link: function(scope, element, attrs) {
scope.$watch(function(){return $location.path();}, function() {
scope.$watch(function dropdownTogglePathWatch(){return $location.path();}, function dropdownTogglePathWatchAction() {
close && close();
});

Expand Down
7 changes: 4 additions & 3 deletions src/ng/anchorScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ function $AnchorScrollProvider() {
// does not scroll when user clicks on anchor link that is currently on
// (no url change, no $locaiton.hash() change), browser native does scroll
if (autoScrollingEnabled) {
$rootScope.$watch(function() {return $location.hash();}, function() {
$rootScope.$evalAsync(scroll);
});
$rootScope.$watch(function autoScrollWatch() {return $location.hash();},
function autoScrollWatchAction() {
$rootScope.$evalAsync(scroll);
});
}

return scroll;
Expand Down
6 changes: 3 additions & 3 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ function $CompileProvider($provide) {
' (directive: ' + newScopeDirective.name + ')');
};
lastValue = scope[scopeName] = parentGet(parentScope);
scope.$watch(function() {
scope.$watch(function parentValueWatch() {
var parentValue = parentGet(parentScope);

if (parentValue !== scope[scopeName]) {
Expand Down Expand Up @@ -996,7 +996,7 @@ function $CompileProvider($provide) {
bindings = parent.data('$binding') || [];
bindings.push(interpolateFn);
safeAddClass(parent.data('$binding', bindings), 'ng-binding');
scope.$watch(interpolateFn, function(value) {
scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
node[0].nodeValue = value;
});
})
Expand Down Expand Up @@ -1026,7 +1026,7 @@ function $CompileProvider($provide) {
attr[name] = undefined;
($$observers[name] || ($$observers[name] = [])).$$inter = true;
(attr.$$observers && attr.$$observers[name].$$scope || scope).
$watch(interpolateFn, function(value) {
$watch(interpolateFn, function interpolateFnWatchAction(value) {
attr.$set(name, value);
});
})
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/booleanAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
priority: 100,
compile: function() {
return function(scope, element, attr) {
scope.$watch(attr[normalized], function(value) {
scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
attr.$set(attrName, !!value);
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$

// model -> value
var ctrl = this;
$scope.$watch(ngModelGet, function(value) {
$scope.$watch(ngModelGet, function ngModelWatchAction(value) {

// ignore change from view
if (ctrl.$modelValue === value) return;
Expand Down Expand Up @@ -1242,7 +1242,7 @@ var ngValueDirective = function() {
};
} else {
return function(scope, elm, attr) {
scope.$watch(attr.ngValue, function(value) {
scope.$watch(attr.ngValue, function valueWatchAction(value) {
attr.$set('value', value, false);
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
var ngBindDirective = ngDirective(function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBind);
scope.$watch(attr.ngBind, function(value) {
scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
element.text(value == undefined ? '' : value);
});
});
Expand Down Expand Up @@ -132,7 +132,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
var ngBindHtmlUnsafeDirective = [function() {
return function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe);
scope.$watch(attr.ngBindHtmlUnsafe, function(value) {
scope.$watch(attr.ngBindHtmlUnsafe, function ngBindHtmlUnsafeWatchAction(value) {
element.html(value || '');
});
};
Expand Down
6 changes: 3 additions & 3 deletions src/ng/directive/ngClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function classDirective(name, selector) {
name = 'ngClass' + name;
return ngDirective(function(scope, element, attr) {
// Reusable function for re-applying the ngClass
function reapply(newVal, oldVal) {
function ngClassWatchAction(newVal, oldVal) {
if (selector === true || scope.$index % 2 === selector) {
if (oldVal && (newVal !== oldVal)) {
if (isObject(oldVal) && !isArray(oldVal))
Expand All @@ -16,11 +16,11 @@ function classDirective(name, selector) {
if (newVal) element.addClass(isArray(newVal) ? newVal.join(' ') : newVal);
}
};
scope.$watch(attr[name], reapply, true);
scope.$watch(attr[name], ngClassWatchAction, true);

attr.$observe('class', function(value) {
var ngClass = scope.$eval(attr[name]);
reapply(ngClass, ngClass);
ngClassWatchAction(ngClass, ngClass);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/ngInclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
element.html('');
};

scope.$watch(srcExp, function(src) {
scope.$watch(srcExp, function ngIncludeWatchAction(src) {
var thisChangeId = ++changeCounter;

if (src) {
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngPluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
offset + endSymbol));
});

scope.$watch(function() {
scope.$watch(function ngPluralizeWatch() {
var value = parseFloat(scope.$eval(numberExp));

if (!isNaN(value)) {
Expand All @@ -199,7 +199,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
} else {
return '';
}
}, function(newVal) {
}, function ngPluralizeWatchAction(newVal) {
element.text(newVal);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var ngRepeatDirective = ngDirective({
// We expect this to be a rare case.
var lastOrder = new HashQueueMap();
var indexValues = [];
scope.$watch(function(scope){
scope.$watch(function ngRepeatWatch(scope){
var index, length,
collection = scope.$eval(rhs),
collectionLength = size(collection, true),
Expand Down Expand Up @@ -131,7 +131,7 @@ var ngRepeatDirective = ngDirective({
} else {
last = undefined;
}

if (last) {
// if we have already seen this object, then we need to reuse the
// associated scope/element
Expand Down Expand Up @@ -187,7 +187,7 @@ var ngRepeatDirective = ngDirective({
for (i = 0, l = indexValues.length - length; i < l; i++) {
indexValues.pop();
}

//shrink children
for (key in lastOrder) {
if (lastOrder.hasOwnProperty(key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngShowHide.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
//TODO(misko): refactor to remove element from the DOM
var ngShowDirective = ngDirective(function(scope, element, attr){
scope.$watch(attr.ngShow, function(value){
scope.$watch(attr.ngShow, function ngShowWatchAction(value){
element.css('display', toBoolean(value) ? '' : 'none');
});
});
Expand Down Expand Up @@ -74,7 +74,7 @@ var ngShowDirective = ngDirective(function(scope, element, attr){
*/
//TODO(misko): refactor to remove element from the DOM
var ngHideDirective = ngDirective(function(scope, element, attr){
scope.$watch(attr.ngHide, function(value){
scope.$watch(attr.ngHide, function ngHideWatchAction(value){
element.css('display', toBoolean(value) ? 'none' : '');
});
});
2 changes: 1 addition & 1 deletion src/ng/directive/ngStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</example>
*/
var ngStyleDirective = ngDirective(function(scope, element, attr) {
scope.$watch(attr.ngStyle, function(newStyles, oldStyles) {
scope.$watch(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) {
if (oldStyles && (newStyles !== oldStyles)) {
forEach(oldStyles, function(val, style) { element.css(style, '');});
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/ngSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var ngSwitchDirective = valueFn({
selectedElement,
selectedScope;

scope.$watch(watchExpr, function(value) {
scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
if (selectedElement) {
selectedScope.$destroy();
selectedElement.remove();
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {

// we have to do it on each watch since ngModel watches reference, but
// we need to work of an array, so we need to see if anything was inserted/removed
scope.$watch(function() {
scope.$watch(function selectMultipleWatch() {
if (!equals(lastView, ctrl.$viewValue)) {
lastView = copy(ctrl.$viewValue);
ctrl.$render();
Expand Down Expand Up @@ -544,7 +544,7 @@ var optionDirective = ['$interpolate', function($interpolate) {
}

if (interpolateFn) {
scope.$watch(interpolateFn, function(newVal, oldVal) {
scope.$watch(interpolateFn, function interpolateWatchAction(newVal, oldVal) {
attr.$set('value', newVal);
if (newVal !== oldVal) selectCtrl.removeOption(oldVal);
selectCtrl.addOption(newVal);
Expand Down
2 changes: 1 addition & 1 deletion src/ngSanitize/directive/ngBindHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
angular.module('ngSanitize').directive('ngBindHtml', ['$sanitize', function($sanitize) {
return function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
scope.$watch(attr.ngBindHtml, function(value) {
scope.$watch(attr.ngBindHtml, function ngBindHtmlWatchAction(value) {
value = $sanitize(value);
element.html(value || '');
});
Expand Down

0 comments on commit 2c6aa4c

Please sign in to comment.