@@ -8,20 +8,37 @@ function updateCountRender(componentId) {
8
8
return count ;
9
9
}
10
10
11
- export default function logRender ( { components } ) {
11
+ function inArray ( componentName , list ) {
12
+ return list . some ( ( item ) => {
13
+ if ( componentName === item ) {
14
+ return true ;
15
+ }
16
+ } ) ;
17
+ }
18
+
19
+ export default function logRender ( { components, imports } ) {
20
+ const options = imports [ 0 ] ;
12
21
return function wrap ( ReactClass , componentId ) {
13
22
const originalRender = ReactClass . prototype . render ;
14
23
const displayName = components [ componentId ] . displayName ;
24
+ let enableLog = true ;
25
+
26
+ if ( options ) {
27
+ enableLog = options . include ? enableLog && inArray ( displayName , options . include ) : enableLog ;
28
+ enableLog = options . exclude ? enableLog && ! inArray ( displayName , options . exclude ) : enableLog ;
29
+ }
15
30
16
- ReactClass . prototype . render = function ( ) {
17
- const count = updateCountRender ( componentId ) ;
18
- console . groupCollapsed ( `render: ${ displayName } (${ count } )` ) ;
19
- console . log ( 'props' , this . props ) ;
20
- console . log ( 'state' , this . state ) ;
21
- console . groupEnd ( ) ;
31
+ if ( enableLog ) {
32
+ ReactClass . prototype . render = function ( ) {
33
+ const count = updateCountRender ( componentId ) ;
34
+ console . groupCollapsed ( `render: ${ displayName } (${ count } )` ) ;
35
+ console . log ( 'props' , this . props ) ;
36
+ console . log ( 'state' , this . state ) ;
37
+ console . groupEnd ( ) ;
22
38
23
- return originalRender . apply ( this , arguments ) ;
24
- } ;
39
+ return originalRender . apply ( this , arguments ) ;
40
+ } ;
41
+ }
25
42
26
43
return ReactClass ;
27
44
} ;
0 commit comments