@@ -3,83 +3,83 @@ import React, { Component } from 'react';
3
3
import hoistNonReactStatics from 'hoist-non-react-statics' ;
4
4
5
5
const Profiler = React . Profiler ;
6
- export default ( WrappedComponent , _id , ip = '127.0.0.1' , events = [ 'mount' , 'update' ] , showLogs = false , port = 8125 , enableWS = true ) => {
7
- const remote = `http://${ ip } :${ port } /value` ;
8
- const log = ( message ) => {
9
- if ( showLogs ) {
10
- console . log ( message ) ;
11
- }
12
- } ;
13
- class HOC extends Component {
14
- static displayName = 'withPerformance' ;
6
+ export default ( { WrappedComponent, _id, ip = '127.0.0.1' , events = [ 'mount' , 'update' ] , showLogs = false , port = 8125 , enableWS = true } ) => {
7
+ const remote = `http://${ ip } :${ port } /value` ;
8
+ const log = ( message ) => {
9
+ if ( showLogs ) {
10
+ console . log ( message ) ;
11
+ }
12
+ } ;
13
+ class HOC extends Component {
14
+ static displayName = 'withPerformance' ;
15
15
16
- constructor ( props ) {
17
- super ( props ) ;
18
- this . state = { } ;
19
- }
16
+ constructor ( props ) {
17
+ super ( props ) ;
18
+ this . state = { } ;
19
+ }
20
20
21
- componentDidMount ( ) {
22
- if ( ! enableWS ) return ;
23
- this . socket = new WebSocket ( `ws://${ ip } :8126` ) ;
24
- this . socket . onopen = function ( ) {
25
- log ( 'RNPM: connected' ) ;
26
- } ;
21
+ componentDidMount ( ) {
22
+ if ( ! enableWS ) return ;
23
+ this . socket = new WebSocket ( `ws://${ ip } :8126` ) ;
24
+ this . socket . onopen = function ( ) {
25
+ log ( 'RNPM: connected' ) ;
26
+ } ;
27
27
28
- this . socket . onmessage = ( event ) => {
29
- switch ( event . data ) {
30
- case 'remount' : {
31
- log ( 'RNPM: remount' ) ;
32
- this . setState ( { unmount : true } , ( ) => {
33
- setTimeout ( ( ) => this . setState ( { unmount : false } ) , 200 ) ;
34
- } ) ;
35
- break ;
36
- }
37
- case 'forceUpdate' : {
38
- log ( 'RNPM: force update' ) ;
39
- this . forceUpdate ( ) ;
40
- break ;
41
- }
42
- default :
43
- break ;
44
- }
45
- } ;
28
+ this . socket . onmessage = ( event ) => {
29
+ switch ( event . data ) {
30
+ case 'remount' : {
31
+ log ( 'RNPM: remount' ) ;
32
+ this . setState ( { unmount : true } , ( ) => {
33
+ setTimeout ( ( ) => this . setState ( { unmount : false } ) , 200 ) ;
34
+ } ) ;
35
+ break ;
36
+ }
37
+ case 'forceUpdate' : {
38
+ log ( 'RNPM: force update' ) ;
39
+ this . forceUpdate ( ) ;
40
+ break ;
41
+ }
42
+ default :
43
+ break ;
46
44
}
45
+ } ;
46
+ }
47
47
48
- componentWillUnmount ( ) {
49
- this . socket && this . socket . close ( ) ;
50
- }
48
+ componentWillUnmount ( ) {
49
+ this . socket && this . socket . close ( ) ;
50
+ }
51
51
52
- logMeasurement = async ( id , phase , actualDuration ) => {
53
- if ( ! events . includes ( phase ) ) {
54
- return ;
55
- }
56
- if ( actualDuration < 0.1 ) {
57
- return ;
58
- }
52
+ logMeasurement = async ( id , phase , actualDuration ) => {
53
+ if ( ! events . includes ( phase ) ) {
54
+ return ;
55
+ }
56
+ if ( actualDuration < 0.1 ) {
57
+ return ;
58
+ }
59
59
60
- if ( remote ) {
61
- fetch ( remote , {
62
- method : 'POST' ,
63
- headers : {
64
- 'Content-Type' : 'application/json' ,
65
- } ,
66
- body : JSON . stringify ( { value : actualDuration } ) ,
67
- } ) ;
68
- }
69
- }
60
+ if ( remote ) {
61
+ fetch ( remote , {
62
+ method : 'POST' ,
63
+ headers : {
64
+ 'Content-Type' : 'application/json' ,
65
+ } ,
66
+ body : JSON . stringify ( { value : actualDuration } ) ,
67
+ } ) ;
68
+ }
69
+ }
70
70
71
- render ( ) {
72
- return this . state . unmount ? null : (
73
- < Profiler id = { _id } onRender = { this . logMeasurement } >
74
- < WrappedComponent
75
- { ...this . props }
76
- { ...this . state }
77
- />
78
- </ Profiler >
71
+ render ( ) {
72
+ return this . state . unmount ? null : (
73
+ < Profiler id = { _id } onRender = { this . logMeasurement } >
74
+ < WrappedComponent
75
+ { ...this . props }
76
+ { ...this . state }
77
+ />
78
+ </ Profiler >
79
79
80
- ) ;
81
- }
80
+ ) ;
82
81
}
82
+ }
83
83
84
- return hoistNonReactStatics ( HOC , WrappedComponent ) ; ;
84
+ return hoistNonReactStatics ( HOC , WrappedComponent ) ;
85
85
} ;
0 commit comments