Skip to content

Commit 47e1022

Browse files
committed
Added simple digest counter
1 parent c1a874e commit 47e1022

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ digest duration for several selectors and print sorted table starting with the s
7777
* [ng-count-digest-cycles.js](ng-count-digest-cycles.js) - counts number of full digest cycles (from the root scope)
7878
that run when a scope method executes. Useful because sometimes you can get away with just a local digest
7979
cycle, rather than a full update. See [Local Angular scopes](http://glebbahmutov.com/blog/local-angular-scopes/).
80+
* [ng-count-digest-cycle-simple.js](ng-count-digest-cycle-simple.js) - keeps counting number of times
81+
the digest cycle runs.
8082
* [ng-throw-error.js](ng-throw-error.js) throws an error from the digest cycle; useful for checking
8183
if your [exception handler](http://glebbahmutov.com/blog/catch-all-errors-in-angular-app/) is working.
8284

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"main": "first-paint.js",
4-
"version": "0.4.1",
4+
"version": "0.5.0",
55
"homepage": "https://github.com/bahmutov/code-snippets",
66
"license": "MIT",
77
"ignore": [

ng-count-digest-cycle-simple.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
uses console to print a message every time
3+
the digest cycle runs.
4+
*/
5+
(function monitorDigestCycle(angular) {
6+
var injector = angular.element(document.body).injector();
7+
if (!injector) {
8+
throw new Error('Missing Angular injector on the document body');
9+
}
10+
var $rootScope = injector.get('$rootScope');
11+
function dummy() {
12+
console.count('digest cycle');
13+
}
14+
window.stopWatching = $rootScope.$watch(dummy);
15+
console.log('run window.stopWatching() to stop watching the digest cycle');
16+
}(window.angular));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"description": "Chrome DevTools code snippets ",
4-
"version": "0.4.1",
4+
"version": "0.5.0",
55
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
66
"bugs": {
77
"url": "https://github.com/bahmutov/code-snippets/issues"

0 commit comments

Comments
 (0)