angular-ui/ui-grid

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

Open

#4,061 建立於 2015年7月28日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)JavaScript (2,496 fork)batch import
help wantedtype: docstype: enhancement

倉庫指標

Star
 (5,395 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南