angular-ui/ui-grid

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

Open

#4.061 aberto em 28 de jul. de 2015

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (2.496 forks)batch import
help wantedtype: docstype: enhancement

Métricas do repositório

Stars
 (5.395 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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.

Guia do colaborador