Skip to content

Instantly share code, notes, and snippets.

@zeapo
Last active August 29, 2015 14:09
Show Gist options
  • Save zeapo/96933274e0af69eb5dd6 to your computer and use it in GitHub Desktop.
Save zeapo/96933274e0af69eb5dd6 to your computer and use it in GitHub Desktop.
List watchers and expressions
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