Skip to content

Commit 1ae4e9b

Browse files
committed
added monitor digest cycle
1 parent 4eb7c82 commit 1ae4e9b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Read [Code Snippets tutorial][1],
2626
[Performance profiling using DevTools code snippets][2] and
2727
[How to improve Angular application performance using code snippets][3].
2828

29+
Note: code snippets do NOT have access to the full console API, for example no access to
30+
`console.monitor`.
31+
2932
## Snippets
3033

3134
### DOM and CPU generic performance
@@ -70,6 +73,7 @@ with given name.
7073
that surrounds given selector. Useful to find parts of the page with expensive watchers.
7174
* [ng-find-expensive-digest.js](ng-find-expensive-digest.js) builds upon ng-profile-local-digest.js to measure
7275
digest duration for several selectors and print sorted table starting with the slowest digest duration.
76+
* [ng-monitor-digest-cycle.js](ng-monitor-digest-cycle.js) - prints a string every time a digest cycle runs.
7377
* [ng-count-digest-cycles.js](ng-count-digest-cycles.js) - counts number of full digest cycles (from the root scope)
7478
that run when a scope method executes. Useful because sometimes you can get away with just a local digest
7579
cycle, rather than a full update. See [Local Angular scopes](http://glebbahmutov.com/blog/local-angular-scopes/).

ng-monitor-digest-cycle.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
uses console.monitor 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.log('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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"devDependencies": {
1212
"eslint-rules": "0.3.0",
1313
"grunt": "0.4.5",
14+
"grunt-cli": "0.1.13",
1415
"grunt-contrib-jshint": "0.11.0",
1516
"grunt-deps-ok": "0.5.2",
1617
"grunt-eslint": "2.1.0",

0 commit comments

Comments
 (0)