@@ -22,51 +22,41 @@ import { Component } from 'preact'
2222import { getActiveGraph , getCredentials , eventToHandler } from './helpers'
2323
2424export default class DesktopIntegration extends Component {
25- state = {
26- listenerSetup : false ,
27- cachedConnectionCredentials : { }
28- }
29- setupListener = props => {
30- if ( this . state . listenerSetup ) return
31- const { integrationPoint } = props
25+ setupListener ( ) {
26+ const { integrationPoint } = this . props
3227 // Run on context updates
3328 if ( integrationPoint && integrationPoint . onContextUpdate ) {
34- const listenerSetup = ( ) =>
35- integrationPoint . onContextUpdate ( ( event , newContext , oldContext ) => {
36- const handlerPropName = eventToHandler ( event . type )
37- if ( ! handlerPropName ) return
38- if ( typeof this . props [ handlerPropName ] === 'undefined' ) return
39- this . props [ handlerPropName ] ( event , newContext , oldContext )
40- } )
41- this . setState ( { listenerSetup : true } , listenerSetup )
29+ integrationPoint . onContextUpdate ( ( event , newContext , oldContext ) => {
30+ const handlerPropName = eventToHandler ( event . type )
31+ if ( ! handlerPropName ) return
32+ if ( typeof this . props [ handlerPropName ] === 'undefined' ) return
33+ this . props [ handlerPropName ] ( event , newContext , oldContext )
34+ } )
4235 }
4336 }
44- checkContextForActiveConnection = props => {
45- const { integrationPoint } = props
37+ checkContextForActiveConnection ( ) {
38+ const { integrationPoint, onMount = null } = this . props
4639 if ( integrationPoint && integrationPoint . getContext ) {
4740 integrationPoint
4841 . getContext ( )
4942 . then ( context => {
5043 const activeGraph = getActiveGraph ( context )
51- if ( this . props . onMount ) {
44+ if ( onMount ) {
5245 const connectionCredentials = getCredentials (
5346 'bolt' ,
5447 activeGraph . connection
5548 )
56- this . props . onMount ( activeGraph , connectionCredentials , context )
49+ onMount ( activeGraph , connectionCredentials , context )
5750 }
5851 } )
5952 . catch ( e => { } ) // Catch but don't bother
6053 }
6154 }
6255 componentDidMount ( ) {
63- this . checkContextForActiveConnection ( this . props )
64- this . setupListener ( this . props )
65- }
66- componentWillReceiveProps ( props ) {
67- this . setupListener ( props )
56+ this . checkContextForActiveConnection ( )
57+ this . setupListener ( )
6858 }
69- render = ( ) => {
59+ render ( ) {
7060 return null
7161 }
7262}
0 commit comments