Last active
August 29, 2015 14:09
-
-
Save zeapo/96933274e0af69eb5dd6 to your computer and use it in GitHub Desktop.
List watchers and expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getWatchers = function() { | |
var watchers, elementsWithScope, scope, i, len; | |
watchers = []; | |
elementsWithScope = document.querySelectorAll('.ng-scope'); | |
for (i = 0, len = elementsWithScope.length; i < len; i++) { | |
scope = angular.element(elementsWithScope[i]).scope(); | |
if (scope.$$watchers != null) { | |
watchers.push(scope.$$watchers); | |
} | |
} | |
return watchers; | |
}; | |
getExpressions = function(watchers) { | |
return _.map(_.flatten(watchers), function(obj) { return obj.exp; }); | |
} | |
// return all the watchers grouped by expression | |
groupByExpression = function(expressions) { | |
if (!expressions) return groupByExpression(getWatchers()); | |
return _.groupBy(_.flatten(expressions), function(obj) { return obj.exp; }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment