help wantedtype: docstype: enhancement
描述
It would be cool to see the number of watchers we had on the grid in a particular demo.
Alternatively it could be a built in function on the grid to get its own stats.
I found this chunk of code on stackoverflow that I modified a bit to see how we were doing.
(function () {
var root = angular.element(document.querySelector('.doc-example-live'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);
});
}
});
angular.forEach(element.children(), function (childElement) {
f(angular.element(childElement));
});
};
f(root);
// Remove duplicate watchers
var watchersWithoutDuplicates = [];
angular.forEach(watchers, function(item) {
if(watchersWithoutDuplicates.indexOf(item) < 0) {
watchersWithoutDuplicates.push(item);
}
});
console.log(watchersWithoutDuplicates.length);
})();
If you want to try it out you can paste it into your dev console when you have a tutorial page open and it will print the number of watchers.