From 1293c53c4bbb4d5a95503ab65c0d952bd5387fbf Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Thu, 18 Jan 2018 12:02:45 +0000 Subject: [PATCH] Cleanup --- src/components/views/elements/AppTile.js | 39 +++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index fd88295122..05ea8cfa0b 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -160,10 +160,30 @@ export default class AppTile extends React.Component { // postMessaging API window.addEventListener('message', this._onMessage, false); - // General event handler + // Widget action listeners this.dispatcherRef = dis.register(this._onWidgetAction); } + componentWillUnmount() { + // Widget action listeners + console.warn('Removing widget event listener', this.dispatcherRef); + dis.unregister(this.dispatcherRef); + + // Widget postMessage listeners + try { + if (this.widgetMessaging) { + this.widgetMessaging.stopListening(); + this.widgetMessaging.removeEndpoint(this.props.id, this.props.url); + } else { + console.warn('WidgetMessaging not initialised. Not stopping.'); + } + } catch (e) { + console.error('Failed to stop listening for widgetMessaging events', e.message); + } + // Jitsi listener + window.removeEventListener('message', this._onMessage); + } + /** * Adds a scalar token to the widget URL, if required * Component initialisation is only complete when this function has resolved @@ -216,23 +236,6 @@ export default class AppTile extends React.Component { }); } - componentWillUnmount() { - // Widget action listeners - dis.unregister(this.dispatcherRef); - - // Widget postMessage listeners - try { - if (this.widgetMessaging) { - this.widgetMessaging.stopListening(); - this.widgetMessaging.removeEndpoint(this.props.id, this.props.url); - } - } catch (e) { - console.error('Failed to stop listening for widgetMessaging events', e.message); - } - // Jitsi listener - window.removeEventListener('message', this._onMessage); - } - componentWillReceiveProps(nextProps) { if (nextProps.url !== this.props.url) { this._getNewState(nextProps);