Created
June 15, 2016 15:32
-
-
Save enricodeleo/09c9814e048fbe682b5258909f6773a9 to your computer and use it in GitHub Desktop.
Count Angularjs 1.x 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
(function countWatchers() | |
{ | |
var root = angular.element(document.getElementsByTagName('body')).injector().get('$rootScope'); | |
var count = root.$$watchers ? root.$$watchers.length : 0; // include the current scope | |
var pendingChildHeads = [root.$$childHead]; | |
var currentScope; | |
while (pendingChildHeads.length) | |
{ | |
currentScope = pendingChildHeads.shift(); | |
while (currentScope) | |
{ | |
count += currentScope.$$watchers ? currentScope.$$watchers.length : 0; | |
pendingChildHeads.push(currentScope.$$childHead); | |
currentScope = currentScope.$$nextSibling; | |
} | |
} | |
return count; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment