Last active
March 31, 2017 06:37
-
-
Save bpceee/b8231f69d6df1ce2ee12faf41e7a6321 to your computer and use it in GitHub Desktop.
walk angular 1.x scope tree
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
function scopeWalker(scope, op) { | |
var _walker = (scope) => { | |
op(scope); | |
var currentChildScope = scope.$$childHead; | |
while(currentChildScope) { | |
_walker(currentChildScope); | |
currentChildScope = currentChildScope.$$nextSibling; | |
} | |
} | |
_walker(scope); | |
} | |
function countWatchers(scope) { | |
var count = 0; | |
scopeWalker(scope, s => { | |
if(s.$$watchers) { | |
count += s.$$watchers.length; | |
console.log(s.$$watchers.length); | |
} | |
}); | |
return count; | |
} | |
function $0Watchers() { | |
return countWatchers($($0).scope()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment