Skip to content

Instantly share code, notes, and snippets.

@bpceee
Last active March 31, 2017 06:37
Show Gist options
  • Save bpceee/b8231f69d6df1ce2ee12faf41e7a6321 to your computer and use it in GitHub Desktop.
Save bpceee/b8231f69d6df1ce2ee12faf41e7a6321 to your computer and use it in GitHub Desktop.
walk angular 1.x scope tree
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