angular-ui/ui-grid

Add Live Stats to Docs (Watcher Count, ect...)

Open

#4 061 ouverte le 28 juil. 2015

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)JavaScript (2 496 forks)batch import
help wantedtype: docstype: enhancement

Métriques du dépôt

Stars
 (5 395 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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.

Guide contributeur