Bladeren bron

Sanity-check decaffeinate app.views.Notif

Simon Legner 1 jaar geleden
bovenliggende
commit
1efb79404f

+ 12 - 27
assets/javascripts/views/misc/news.js

@@ -1,23 +1,11 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Sanity-check the conversion and remove this comment.
-/*
- * decaffeinate suggestions:
- * DS101: Remove unnecessary use of Array.from
- * DS102: Remove unnecessary code created because of implicit returns
- * DS205: Consider reworking code to avoid use of IIFEs
- * DS206: Consider reworking classes to avoid initClass
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
 //= require views/misc/notif
 
 app.views.News = class News extends app.views.Notif {
-  static initClass() {
-    this.className += " _notif-news";
+  static className = "_notif _notif-news";
 
-    this.defautOptions = { autoHide: 30000 };
-  }
+  static defaultOptions = { autoHide: 30000 };
 
-  init() {
+  init0() {
     this.unreadNews = this.getUnreadNews();
     if (this.unreadNews.length) {
       this.show();
@@ -30,21 +18,19 @@ app.views.News = class News extends app.views.Notif {
   }
 
   getUnreadNews() {
-    let time;
-    if (!(time = this.getLastReadTime())) {
+    let time = this.getLastReadTime();
+    if (!time) {
       return [];
     }
 
-    return (() => {
-      const result = [];
-      for (var news of Array.from(app.news)) {
-        if (new Date(news[0]).getTime() <= time) {
-          break;
-        }
-        result.push(news);
+    const result = [];
+    for (var news of app.news) {
+      if (new Date(news[0]).getTime() <= time) {
+        break;
       }
-      return result;
-    })();
+      result.push(news);
+    }
+    return result;
   }
 
   getLastNewsTime() {
@@ -59,4 +45,3 @@ app.views.News = class News extends app.views.Notif {
     app.settings.set("news", this.getLastNewsTime());
   }
 };
-app.views.News.initClass();

+ 2 - 12
assets/javascripts/views/misc/notice.js

@@ -1,15 +1,6 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Sanity-check the conversion and remove this comment.
-/*
- * decaffeinate suggestions:
- * DS206: Consider reworking classes to avoid initClass
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
 app.views.Notice = class Notice extends app.View {
-  static initClass() {
-    this.className = "_notice";
-    this.attributes = { role: "alert" };
-  }
+  static className = "_notice";
+  static attributes = { role: "alert" };
 
   constructor(type, ...args) {
     super();
@@ -44,4 +35,3 @@ app.views.Notice = class Notice extends app.View {
     $.remove(this.el);
   }
 };
-app.views.Notice.initClass();

+ 9 - 18
assets/javascripts/views/misc/notif.js

@@ -1,29 +1,21 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Sanity-check the conversion and remove this comment.
-/*
- * decaffeinate suggestions:
- * DS206: Consider reworking classes to avoid initClass
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
 app.views.Notif = class Notif extends app.View {
-  static initClass() {
-    this.className = "_notif";
-    this.activeClass = "_in";
-    this.attributes = { role: "alert" };
+  static className = "_notif";
+  static activeClass = "_in";
+  static attributes = { role: "alert" };
 
-    this.defaultOptions = { autoHide: 15000 };
+  static defaultOptions = { autoHide: 15000 };
 
-    this.events = { click: "onClick" };
-  }
+  static events = { click: "onClick" };
 
   constructor(type, options) {
     super();
     this.type = type;
     this.options = $.extend({}, this.constructor.defaultOptions, options || {});
+    this.init0(); // needs this.options
+    this.refreshElements();
   }
 
-  init() {
+  init0() {
     this.show();
   }
 
@@ -55,7 +47,7 @@ app.views.Notif = class Notif extends app.View {
   }
 
   position() {
-    const notifications = $$(`.${app.views.Notif.className}`);
+    const notifications = $$(`.${Notif.className}`);
     if (notifications.length) {
       const lastNotif = notifications[notifications.length - 1];
       this.el.style.top =
@@ -77,4 +69,3 @@ app.views.Notif = class Notif extends app.View {
     }
   }
 };
-app.views.Notif.initClass();

+ 2 - 12
assets/javascripts/views/misc/tip.js

@@ -1,21 +1,11 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Sanity-check the conversion and remove this comment.
-/*
- * decaffeinate suggestions:
- * DS206: Consider reworking classes to avoid initClass
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
 //= require views/misc/notif
 
 app.views.Tip = class Tip extends app.views.Notif {
-  static initClass() {
-    this.className = "_notif _notif-tip";
+  static className = "_notif _notif-tip";
 
-    this.defautOptions = { autoHide: false };
-  }
+  static defautOptions = { autoHide: false };
 
   render() {
     this.html(this.tmpl(`tip${this.type}`));
   }
 };
-app.views.Tip.initClass();

+ 12 - 27
assets/javascripts/views/misc/updates.js

@@ -1,23 +1,11 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Sanity-check the conversion and remove this comment.
-/*
- * decaffeinate suggestions:
- * DS101: Remove unnecessary use of Array.from
- * DS102: Remove unnecessary code created because of implicit returns
- * DS205: Consider reworking code to avoid use of IIFEs
- * DS206: Consider reworking classes to avoid initClass
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
 //= require views/misc/notif
 
 app.views.Updates = class Updates extends app.views.Notif {
-  static initClass() {
-    this.className += " _notif-news";
+  static className = "_notif _notif-news";
 
-    this.defautOptions = { autoHide: 30000 };
-  }
+  static defautOptions = { autoHide: 30000 };
 
-  init() {
+  init0() {
     this.lastUpdateTime = this.getLastUpdateTime();
     this.updatedDocs = this.getUpdatedDocs();
     this.updatedDisabledDocs = this.getUpdatedDisabledDocs();
@@ -46,18 +34,16 @@ app.views.Updates = class Updates extends app.views.Notif {
     if (!this.lastUpdateTime) {
       return [];
     }
-    return (() => {
-      const result = [];
-      for (var doc of Array.from(app.disabledDocs.all())) {
-        if (
-          doc.mtime > this.lastUpdateTime &&
-          app.docs.findBy("slug_without_version", doc.slug_without_version)
-        ) {
-          result.push(doc);
-        }
+    const result = [];
+    for (var doc of Array.from(app.disabledDocs.all())) {
+      if (
+        doc.mtime > this.lastUpdateTime &&
+        app.docs.findBy("slug_without_version", doc.slug_without_version)
+      ) {
+        result.push(doc);
       }
-      return result;
-    })();
+    }
+    return result;
   }
 
   getLastUpdateTime() {
@@ -73,4 +59,3 @@ app.views.Updates = class Updates extends app.views.Notif {
     );
   }
 };
-app.views.Updates.initClass();