Better countWatchers
The old one missed a few, two on the input and the one in the title. This version also doesn't use jQuery From: http://stackoverflow.com/a/18539624 by StackOverflow user "plantian"
This commit is contained in:
parent
26d43fa694
commit
1d2e5f1d0b
1 changed files with 14 additions and 16 deletions
|
@ -491,24 +491,22 @@ function($rootScope,
|
||||||
|
|
||||||
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
||||||
|
|
||||||
|
// From: http://stackoverflow.com/a/18539624 by StackOverflow user "plantian"
|
||||||
$rootScope.countWatchers = function () {
|
$rootScope.countWatchers = function () {
|
||||||
var root = $(document.getElementsByTagName('body'));
|
var q = [$rootScope], watchers = 0, scope;
|
||||||
var watchers = [];
|
while (q.length > 0) {
|
||||||
|
scope = q.pop();
|
||||||
var f = function (element) {
|
if (scope.$$watchers) {
|
||||||
if (element.data().hasOwnProperty('$scope')) {
|
watchers += scope.$$watchers.length;
|
||||||
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
|
|
||||||
watchers.push(watcher);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (scope.$$childHead) {
|
||||||
angular.forEach(element.children(), function (childElement) {
|
q.push(scope.$$childHead);
|
||||||
f($(childElement));
|
}
|
||||||
});
|
if (scope.$$nextSibling) {
|
||||||
};
|
q.push(scope.$$nextSibling);
|
||||||
|
}
|
||||||
f(root);
|
}
|
||||||
console.log(watchers.length);
|
console.log(watchers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue