Skip to content

Instantly share code, notes, and snippets.

@xavhan
Created May 21, 2015 15:57
Show Gist options
  • Save xavhan/d7d806bf2f22a0e1d8cc to your computer and use it in GitHub Desktop.
Save xavhan/d7d806bf2f22a0e1d8cc to your computer and use it in GitHub Desktop.
//count($0); for counting watchers on the selected dom element
//count($0, true); for counting watchers on the selected dom element + childrens
function count(el, recurs) {
var root = $(el);
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
if (recurs) {
angular.forEach(element.children(), function (childElement) {
f($(childElement));
});
}
};
f(root);
//console.table(watchers, ['exp', 'last']);
angular.forEach(watchers, function (watcher, index){
console.log('================ ' + (index + 1) + ' ==================');
console.log('watcher.exp :', watcher.exp);
console.log('watcher.last :', watcher.last);
});
console.log('================ total ==================');
console.log(watchers.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment