From 35f2aa32e52084bd5624f9bff517857d20d01665 Mon Sep 17 00:00:00 2001
From: Mathis Neumann <mathis@simpletechs.net>
Date: Mon, 11 Jul 2016 18:24:50 +0200
Subject: [PATCH] avoid listener leaks when the user leaves the view

---
 app/components/architecture-viewer.js                | 12 ++++++++++--
 .../component.js                                     |  7 ++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/app/components/architecture-viewer.js b/app/components/architecture-viewer.js
index ad39f58..d306e7a 100644
--- a/app/components/architecture-viewer.js
+++ b/app/components/architecture-viewer.js
@@ -17,14 +17,22 @@ export default Ember.Component.extend({
         'concentric',
         'breadthfirst'
     ],
+    resizing: false,
     init() {
         this._super();
         this.debug('init!', this.get('graph'), this.get('layoutAlgorithm'));
 
         // add class while the sidebar grows
         const visualisationEvents = this.get('visualisationEvents');
-        visualisationEvents.on('resize:start', () => this.set('resizing', true));
-        visualisationEvents.on('resize:end', () => this.set('resizing', false));
+        const startListener = () => this.set('resizing', true);
+        const endListener = () => this.set('resizing', false);
+        visualisationEvents.on('resize:start', startListener);
+        visualisationEvents.on('resize:end', endListener);
+
+        this.on('willDestroyElement', () => {
+            visualisationEvents.off('resize:start', startListener);
+            visualisationEvents.off('resize:end', endListener);
+        });
     },
     actions: {
         selectLayoutAlgorithm(value) {
diff --git a/app/components/architecture-visualisation-cytoscape/component.js b/app/components/architecture-visualisation-cytoscape/component.js
index 8d1fb25..dc0bf6c 100644
--- a/app/components/architecture-visualisation-cytoscape/component.js
+++ b/app/components/architecture-visualisation-cytoscape/component.js
@@ -19,7 +19,12 @@ export default Ember.Component.extend({
         this.debug('loaded', this.get('graph'));
 
         // we only need to listen to :end since opacity changes are done via css, since architecture-viewer adds a resizing class
-        this.get('visualisationEvents').on('resize:end', this.resize.bind(this));
+        const visualisationEvents = this.get('visualisationEvents');
+        const resizeListener = this.resize.bind(this);
+        visualisationEvents.on('resize:end', resizeListener);
+        this.on('willDestroyElement', () => {
+            visualisationEvents.off('resize:start', resizeListener);
+        });
     },
     willDestroyElement() {
         clearInterval(this.interval);
-- 
GitLab