File tree Expand file tree Collapse file tree 1 file changed +23
-12
lines changed Expand file tree Collapse file tree 1 file changed +23
-12
lines changed Original file line number Diff line number Diff line change 11// taken from http://ng.malsup.com/#!/counting-watchers
2- ( function countAngularWatchers ( ) {
2+ ( function countAngularWatchers ( angular ) {
33 var i , data , scope ,
4- count = 0 ,
5- all = document . all ,
6- len = all . length ,
7- test = { } ;
4+ count = 0 ,
5+ all = document . all ,
6+ len = all . length ,
7+ test = { } ;
8+
9+ var mostWatchers = 0 ;
10+
11+ function countScopeWatchers ( scope , element ) {
12+ test [ scope . $id ] = true ;
13+ var n = scope . $$watchers . length ;
14+ count += n ;
15+ if ( n > mostWatchers ) {
16+ console . log ( 'most watchers' , n ) ;
17+ console . log ( element ) ;
18+ mostWatchers = n ;
19+ }
20+ }
821
922 // go through each element. Count watchers if it has scope or isolate scope
10- /* eslint no-for-loops:0 */
11- for ( i = 0 ; i < len ; i ++ ) {
12- /* global angular */
13- data = angular . element ( all [ i ] ) . data ( ) ;
23+ for ( i = 0 ; i < len ; i += 1 ) {
24+ var el = angular . element ( all [ i ] ) ;
25+ data = el . data ( ) ;
1426 scope = data . $scope || data . $isolateScope ;
1527 if ( scope && scope . $$watchers ) {
1628 if ( ! test [ scope . $id ] ) {
17- test [ scope . $id ] = true ;
18- count += scope . $$watchers . length ;
29+ countScopeWatchers ( scope , el ) ;
1930 }
2031 }
2132 }
2233 console . log ( 'this page has' , count , 'angular watchers' ) ;
2334 return count ;
24- } ) ( ) ;
35+ } ( window . angular ) ) ;
You can’t perform that action at this time.
0 commit comments