angular-ui/ui-grid

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

Open

#4061 aperta il 28 lug 2015

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (2496 fork)batch import
help wantedtype: docstype: enhancement

Metriche repository

Star
 (5395 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor