File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff 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.
7073that 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
7275digest 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)
7478that run when a scope method executes. Useful because sometimes you can get away with just a local digest
7579cycle, rather than a full update. See [ Local Angular scopes] ( http://glebbahmutov.com/blog/local-angular-scopes/ ) .
Original file line number Diff line number Diff line change 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 ) ) ;
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments