Last active
August 29, 2015 14:09
-
-
Save jerry4/c07ad6e892a1ca30ed74 to your computer and use it in GitHub Desktop.
ng app debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (jerry) { alert("already added ngHelpers"); } // | |
var jerry = (function(){ | |
var count = 0; | |
var unregisterDigestWatch = function() {}; // init empty | |
function registerDigestWatch(scope) { | |
scope = scope || angular.element(document).scope(); | |
unregisterDigestWatch = scope.$watch(function() { | |
var c = count++; | |
console.log("Digest " + c +" START..."); | |
var start = performance.now(); | |
scope.$$postDigest(function() { | |
console.log("Digest " + c + " stoped " + (performance.now() - start)); | |
}); | |
}); | |
} | |
function steadyDigestTimer() { | |
var scope = angular.element(document); | |
scope.injector().invoke( function($rootScope) { | |
var a = performance.now(); | |
$rootScope.$apply(); | |
console.log(performance.now() - a + " ms"); | |
}); | |
} | |
function getWatchers(root) { | |
root = angular.element(root || document.documentElement); | |
var watcherCount = 0; | |
function getElemWatchers(element) { | |
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope); | |
var scopeWatchers = getWatchersFromScope(element.data().$scope); | |
var watchers = scopeWatchers.concat(isolateWatchers); | |
angular.forEach(element.children(), function (childElement) { | |
watchers = watchers.concat(getElemWatchers(angular.element(childElement))); | |
}); | |
return watchers; | |
} | |
function getWatchersFromScope(scope) { | |
if (scope) { | |
return scope.$$watchers || []; | |
} else { | |
return []; | |
} | |
} | |
return getElemWatchers(root); | |
} | |
return { | |
registerDigestWatch: registerDigestWatch, | |
unregisterDigestWatch: function() { unregisterDigestWatch(); }, | |
resetDigestCount: function() { count = 0; }, | |
//registerDigest: registerDigest | |
steadyDigestTimer: steadyDigestTimer, | |
getWatchCount: function(scope) { getWatchers(scope).length; } | |
}; | |
})(); | |
jerry.registerDigestWatch(); | |
jerry.steadyDigestTimer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment