Created
March 20, 2015 17:06
-
-
Save kratob/5b8ab643abab86154c18 to your computer and use it in GitHub Desktop.
Bookmarklet to count angular watchers
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
javascript: (function() { | |
function getWatchCount() { | |
var total = 0; | |
var scopeIds = {}; | |
angular.forEach( | |
document.querySelectorAll( ".ng-scope , .ng-isolate-scope" ), | |
countWatchersInNode | |
); | |
return( total ); | |
function countWatchersInNode( node ) { | |
var element = angular.element( node ); | |
if ( element.hasClass( "ng-isolate-scope" ) && element.isolateScope ) { | |
countWatchersInScope( element.isolateScope() ); | |
} | |
if ( element.hasClass( "ng-scope" ) ) { | |
countWatchersInScope( element.scope() ); | |
} | |
} | |
function countWatchersInScope( scope ) { | |
if ( scopeIds.hasOwnProperty( scope.$id ) ) { | |
return; | |
} | |
scopeIds[ scope.$id ] = true; | |
if ( scope.$$watchers ) { | |
total += scope.$$watchers.length; | |
} | |
} | |
} | |
console.log("TOTAL WATCHERS: " + getWatchCount()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment