@@ -3,83 +3,83 @@ import React, { Component } from 'react';
33import hoistNonReactStatics from 'hoist-non-react-statics' ;
44
55const 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' ;
1515
16- constructor ( props ) {
17- super ( props ) ;
18- this . state = { } ;
19- }
16+ constructor ( props ) {
17+ super ( props ) ;
18+ this . state = { } ;
19+ }
2020
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+ } ;
2727
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 ;
4644 }
45+ } ;
46+ }
4747
48- componentWillUnmount ( ) {
49- this . socket && this . socket . close ( ) ;
50- }
48+ componentWillUnmount ( ) {
49+ this . socket && this . socket . close ( ) ;
50+ }
5151
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+ }
5959
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+ }
7070
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 >
7979
80- ) ;
81- }
80+ ) ;
8281 }
82+ }
8383
84- return hoistNonReactStatics ( HOC , WrappedComponent ) ; ;
84+ return hoistNonReactStatics ( HOC , WrappedComponent ) ;
8585} ;
0 commit comments