Created
August 4, 2014 13:32
-
-
Save a-laughlin/de797c4090df84ae5b80 to your computer and use it in GitHub Desktop.
Bookmarklet to count AngularJS watches
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
// Instructions - create a bookmark. Save this code as the url. | |
// Click the bookmarklet to see watch count output in the console. | |
// Currently counts watches by nodeName. It would be more useful by class. TBD. | |
javascript: (function () { | |
var totalWatches = 0; | |
var watchesByElem = {}; | |
angular.forEach(angular.element('.ng-scope'), function (elem) { | |
var s = angular.element(elem).scope(); | |
var w = s.$$watchers; | |
if (s.$$watchers) { | |
watchesByElem[elem.nodeName] = watchesByElem[elem.nodeName]||0; | |
totalWatches += w.length; | |
watchesByElem[elem.nodeName] += w.length; | |
} | |
}); | |
console.log('Total Watches # ',totalWatches); | |
console.log('Breakdown by nodeName:'); | |
for(var name in watchesByElem){ | |
console.log(name,watchesByElem[name]); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍