11import React , { Component } from 'react' ;
22import hoistStatics from 'hoist-non-react-statics' ;
3- import PropTypes from 'prop-types' ;
43
54import * as constants from './constants' ;
65import * as ActionCreators from './redux/actionCreators' ;
@@ -10,6 +9,7 @@ import { MConstructor, MShouldUpdate, MRender, MDidMount,
109 MDidUpdate , MWillUnmount , MSetState , MGetDerivedState , MGetSnapshot ,
1110 MWillMount , MWillReceiveProps , MWillUpdate ,
1211 MUnsafeWillMount , MUnsafeWillReceiveProps , MUnsafeWillUpdate } from './constants' ;
12+ import { store as lifecycleVisualizerStore } from './redux/VisualizerProvider' ;
1313
1414const instanceIdCounters = { } ;
1515
@@ -189,26 +189,21 @@ export default function traceLifecycle(ComponentToTrace) {
189189 this . LifecyclePanel = WrappedLifecyclePanel ;
190190
191191 this . trace = ( methodName ) => {
192- this . context [ constants . reduxStoreKey ] . dispatch (
193- ActionCreators . trace ( componentToTraceName , instanceId , methodName )
194- ) ;
195- } ;
192+ // Just dispatch on lifecycleVisualizerStore directly, rather than introducing complexity by using context.
193+ lifecycleVisualizerStore . dispatch (
194+ ActionCreators . trace ( componentToTraceName , instanceId , methodName )
195+ ) ;
196+ } ;
196197 }
197198
198199 render ( ) {
199200 return < TracedComponent LifecyclePanel = { this . LifecyclePanel } trace = { this . trace } { ...this . props } /> ;
200201 }
201202
202- // Get store directly from context, to prevent introducing extra `Connect` component.
203- static contextTypes = {
204- ...ComponentToTrace . contextTypes , // preserve contextTypes from ComponentToTrace
205- [ constants . reduxStoreKey ] : PropTypes . object
206- }
207-
208203 static displayName = `traceLifecycle(${ componentToTraceName } )` ;
209204 }
210205
211- // Removing the inappropriate methods is simpler than adding appropriate methods to prototype
206+ // Removing the inappropriate methods is simpler than adding appropriate methods to prototype.
212207 if ( isLegacy ) {
213208 delete TracedComponent . getDerivedStateFromProps ;
214209 delete TracedComponent . prototype . getSnapshotBeforeUpdate ;
0 commit comments