REFACTOR: old patterns, deprecations and dead code (#35)

REFACTOR: old patterns, deprecations and dead code (#35)

diff --git a/assets/javascripts/discourse/components/explorer-container.js.es6 b/assets/javascripts/discourse/components/explorer-container.js.es6
index 2f1629c..adf7244 100644
--- a/assets/javascripts/discourse/components/explorer-container.js.es6
+++ b/assets/javascripts/discourse/components/explorer-container.js.es6
@@ -15,19 +15,19 @@ export default Ember.Component.extend({
     if (this._state !== "inDOM") {
       return;
     }
-    const $editPane = this.$(".query-editor");
+    const $editPane = $(".query-editor");
     if (!$editPane.length) {
       return;
     }
 
-    const oldGrippie = this.get("grippie");
+    const oldGrippie = this.grippie;
     if (oldGrippie) {
       oldGrippie.off("mousedown mousemove mouseup");
     }
 
     const $grippie = $editPane.find(".grippie");
     const $target = $editPane.find(".panels-flex");
-    const $document = Ember.$(document);
+    const $document = $(document);
 
     const minWidth = $target.width();
     const minHeight = $target.height();
@@ -35,11 +35,11 @@ export default Ember.Component.extend({
     this.set("grippie", $grippie);
 
     const mousemove = e => {
-      const diffY = this.get("startY") - e.screenY;
-      const diffX = this.get("startX") - e.screenX;
+      const diffY = this.startY - e.screenY;
+      const diffX = this.startX - e.screenX;
 
-      const newHeight = Math.max(minHeight, this.get("startHeight") - diffY);
-      const newWidth = Math.max(minWidth, this.get("startWidth") - diffX);
+      const newHeight = Math.max(minHeight, this.startHeight - diffY);
+      const newWidth = Math.max(minWidth, this.startWidth - diffX);
 
       $target.height(newHeight);
       $target.width(newWidth);
@@ -78,14 +78,16 @@ export default Ember.Component.extend({
   },
 
   didInsertElement() {
-    this._super();
+    this._super(...arguments);
+
     this._bindControls();
   },
 
   willDestroyElement() {
-    this._super();
-    if (this.get("everEditing")) {
-      this.get("grippie").off("mousedown");
+    this._super(...arguments);
+
+    if (this.everEditing) {
+      this.grippie && this.grippie.off("mousedown");
       this.set("grippie", null);
     }
   }
diff --git a/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6 b/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6
index 42222f7..ba2c1f2 100644
--- a/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6
+++ b/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6
@@ -1,8 +1,10 @@
+import { default as computed } from "ember-addons/ember-computed-decorators";
+
 export default Ember.Component.extend({
   tagName: "ol",
 
-  enuminfo: function() {
-    const hash = this.get("col.enum");
+  @computed("col.enum")
+  enuminfo(hash) {
     let result = [];
     for (let key in hash) {
       if (!hash.hasOwnProperty(key)) {
@@ -11,5 +13,5 @@ export default Ember.Component.extend({
       result.push({ value: key, name: hash[key] });
     }
     return result;
-  }.property("col.enum")
+  }
 });
diff --git a/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6 b/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6
index 3b3f147..af1036d 100644
--- a/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6
+++ b/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6
@@ -1,22 +1,25 @@
+import { on } from "ember-addons/ember-computed-decorators";
+
 export default Ember.Component.extend({
   classNameBindings: [":schema-table", "open"],
   tagName: "li",
 
-  open: Ember.computed.alias("table.open"),
+  open: Ember.computed.reads("table.open"),
 
-  _bindClicks: function() {
-    const self = this;
-    this.$()
+  @on("didInsertElement")
+  _bindClicks() {
+    $(this.element)
       .find(".schema-table-name")
-      .click(function(e) {
-        self.set("open", !self.get("open"));
+      .click(e => {
+        this.set("open", !this.open);
         e.preventDefault();
       });
-  }.on("didInsertElement"),
+  },
 
-  _cleanup: function() {
-    this.$()
+  @on("willDestroyElement")
+  _cleanup() {
+    $(this.element)
       .find(".schema-table-name")
       .off("click");
-  }.on("willDestroyElement")
+  }
 });
diff --git a/assets/javascripts/discourse/components/explorer-schema.js.es6 b/assets/javascripts/discourse/components/explorer-schema.js.es6
index 8e1f3f7..6f1d51b 100644
--- a/assets/javascripts/discourse/components/explorer-schema.js.es6
+++ b/assets/javascripts/discourse/components/explorer-schema.js.es6
@@ -1,3 +1,7 @@
+import {
+  default as computed,
+  observes
+} from "ember-addons/ember-computed-decorators";
 import debounce from "discourse/lib/debounce";
 
 export default Ember.Component.extend({
@@ -7,15 +11,14 @@ export default Ember.Component.extend({
     }
   },
 
-  transformedSchema: function() {
-    const schema = this.get("schema");
-
+  @computed("schema")
+  transformedSchema(schema) {
     for (let key in schema) {
       if (!schema.hasOwnProperty(key)) {
         continue;
       }
 
-      schema[key].forEach(function(col) {
+      schema[key].forEach(col => {
         const notes_components = [];
         if (col.primary) {
           notes_components.push("primary key");
@@ -46,17 +49,18 @@ export default Ember.Component.extend({
       });
     }
     return schema;
-  }.property("schema"),
+  },
 
-  rfilter: function() {
-    if (!Ember.isBlank(this.get("filter"))) {
-      return new RegExp(this.get("filter"));
+  @computed("filter")
+  rfilter(filter) {
+    if (!Ember.isBlank(filter)) {
+      return new RegExp(filter);
     }
-  }.property("filter"),
+  },
 
-  filterTables: function(schema) {
+  filterTables(schema) {
     let tables = [];
-    const filter = this.get("rfilter"),
+    const filter = this.rfilter,
       haveFilter = !!filter;
 
     for (let key in schema) {
@@ -89,7 +93,7 @@ export default Ember.Component.extend({
       } else {
         // filter the columns
         let filterCols = [];
-        schema[key].forEach(function(col) {
+        schema[key].forEach(col => {
           if (filter.source === col.column_name) {
             filterCols.unshift(col);
           } else if (filter.test(col.column_name)) {
@@ -108,20 +112,20 @@ export default Ember.Component.extend({
     return tables;
   },
 
+  @observes("filter")
   triggerFilter: debounce(function() {
-    this.set(
-      "filteredTables",
-      this.filterTables(this.get("transformedSchema"))
-    );
+    this.set("filteredTables", this.filterTables(this.transformedSchema));
     this.set("loading", false);
-  }, 500).observes("filter"),
+  }, 500),
 
-  setLoading: function() {
+  @observes("filter")
+  setLoading() {
     this.set("loading", true);
-  }.observes("filter"),
+  },
 
   init() {
-    this._super();
+    this._super(...arguments);
+
     this.set("loading", true);
     this.triggerFilter();
   }
diff --git a/assets/javascripts/discourse/components/hljs-code-view.js.es6 b/assets/javascripts/discourse/components/hljs-code-view.js.es6
index 5431e54..bcacc7a 100644
--- a/assets/javascripts/discourse/components/hljs-code-view.js.es6
+++ b/assets/javascripts/discourse/components/hljs-code-view.js.es6
@@ -1,3 +1,4 @@
+import { on, observes } from "ember-addons/ember-computed-decorators";
 import debounce from "discourse/lib/debounce";
 import highlightSyntax from "discourse/lib/highlight-syntax";
 import { bufferedRender } from "discourse-common/lib/buffered-render";
@@ -5,17 +6,19 @@ import { bufferedRender } from "discourse-common/lib/buffered-render";
 export default Ember.Component.extend(
   bufferedRender({
     buildBuffer(buffer) {
-      buffer.push("<pre><code class='" + this.get("codeClass") + "'>");
-      buffer.push(Handlebars.Utils.escapeExpression(this.get("value")));
+      buffer.push("<pre><code class='" + this.codeClass + "'>");
+      buffer.push(Handlebars.Utils.escapeExpression(this.value));
       buffer.push("</code></pre>");
     },
 
+    @observes("value")

[... diff too long, it was truncated ...]

GitHub sha: b9169ec2

1 Like