Created
May 21, 2015 15:57
-
-
Save xavhan/d7d806bf2f22a0e1d8cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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