DEV: adds teardownComponent hook to connector class (#8171)

DEV: adds teardownComponent hook to connector class (#8171)

This is the counterpart to setupComponent and allows you to clean any observers or state when the component is destroyed.

diff --git a/app/assets/javascripts/discourse/components/plugin-connector.js.es6 b/app/assets/javascripts/discourse/components/plugin-connector.js.es6
index b5df63a..7659014 100644
--- a/app/assets/javascripts/discourse/components/plugin-connector.js.es6
+++ b/app/assets/javascripts/discourse/components/plugin-connector.js.es6
@@ -16,6 +16,13 @@ export default Ember.Component.extend({
     this.set("actions", connectorClass.actions);
   },
 
+  willDestroyElement() {
+    this._super(...arguments);
+
+    const connectorClass = this.get("connector.connectorClass");
+    connectorClass.teardownComponent.call(this, this);
+  },
+
   @observes("args")
   _argsChanged() {
     const args = this.args || {};
diff --git a/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
index 3b81774..b58d198 100644
--- a/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
+++ b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
@@ -17,7 +17,8 @@ export function extraConnectorClass(name, obj) {
 const DefaultConnectorClass = {
   actions: {},
   shouldRender: () => true,
-  setupComponent() {}
+  setupComponent() {},
+  teardownComponent() {}
 };
 
 function findOutlets(collection, callback) {

GitHub sha: 49a4b0dd