DEV: replaces setTimeout by Ember.run.later (#6618)

DEV: replaces setTimeout by Ember.run.later (#6618)

From 907cf3ee2fe902fbbf524b29c0faff0f82b1a8ef Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Mon, 19 Nov 2018 10:46:38 +0100
Subject: [PATCH] DEV: replaces setTimeout by Ember.run.later (#6618)


diff --git a/app/assets/javascripts/admin/controllers/admin-customize-colors-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-customize-colors-show.js.es6
index ca62835..9b83dba 100644
--- a/app/assets/javascripts/admin/controllers/admin-customize-colors-show.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-customize-colors-show.js.es6
@@ -40,7 +40,7 @@ export default Ember.Controller.extend({
         );
       }
 
-      setTimeout(() => {
+      Ember.run.later(() => {
         this.set("model.savingStatus", null);
       }, 2000);
 
diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6
index 1227e86..ce9b6a5 100644
--- a/app/assets/javascripts/discourse/components/composer-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6
@@ -786,7 +786,7 @@ export default Ember.Component.extend({
 
           // The paste doesn't finish immediately and we don't have any onpaste
           // event, so wait for 100ms which _should_ be enough time.
-          setTimeout(() => {
+          Ember.run.later(() => {
             const pastedImg = contentEditableDiv.find("img");
 
             if (pastedImg.length === 1) {
diff --git a/app/assets/javascripts/discourse/initializers/asset-version.js.es6 b/app/assets/javascripts/discourse/initializers/asset-version.js.es6
index 8a93905..980e21e 100644
--- a/app/assets/javascripts/discourse/initializers/asset-version.js.es6
+++ b/app/assets/javascripts/discourse/initializers/asset-version.js.es6
@@ -16,7 +16,7 @@ export default {
       if (!timeoutIsSet && Discourse.get("requiresRefresh")) {
         // Since we can do this transparently for people browsing the forum
         //  hold back the message 24 hours.
-        setTimeout(function() {
+        Ember.run.later(() => {
           bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(
             result
           ) {
diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6
index 1ce5493..1da282b 100644
--- a/app/assets/javascripts/discourse/lib/click-track.js.es6
+++ b/app/assets/javascripts/discourse/lib/click-track.js.es6
@@ -114,7 +114,7 @@ export default {
     }
 
     // restore href
-    setTimeout(() => {
+    Ember.run.later(() => {
       $link.removeClass("no-href");
       $link.attr("href", $link.data("href"));
       $link.data("href", null);
diff --git a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6
index 06264d5..5b26fce 100644
--- a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6
+++ b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6
@@ -79,7 +79,7 @@ function confirmNotification() {
   const clickEventHandler = () => notification.close();
 
   notification.addEventListener("click", clickEventHandler);
-  setTimeout(() => {
+  Ember.run.later(() => {
     notification.close();
     notification.removeEventListener("click", clickEventHandler);
   }, 10 * 1000);
@@ -177,7 +177,7 @@ function onNotification(data) {
     }
 
     notification.addEventListener("click", clickEventHandler);
-    setTimeout(function() {
+    Ember.run.later(() => {
       notification.close();
       notification.removeEventListener("click", clickEventHandler);
     }, 10 * 1000);
diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
index 31f1c9a..0e43e1e 100644
--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
@@ -130,9 +130,7 @@ export default {
   quoteReply() {
     this.sendToSelectedPost("replyToPost");
     // lazy but should work for now
-    setTimeout(function() {
-      $(".d-editor .quote").click();
-    }, 500);
+    Ember.run.later(() => $(".d-editor .quote").click(), 500);
   },
 
   goToFirstPost() {
diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
index d2e228f..8c7c9df 100644
--- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
+++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
@@ -86,9 +86,7 @@ function positioningWorkaround($fixedElement) {
       fixedElement.style.top = "";
       fixedElement.style.height = oldHeight;
 
-      setTimeout(() => {
-        $(fixedElement).removeClass("no-transition");
-      }, 500);
+      Ember.run.later(() => $(fixedElement).removeClass("no-transition"), 500);
 
       $(window).scrollTop(originalScrollTop);
 
diff --git a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6
index f73c739..d5d7ff0 100644
--- a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6
+++ b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6
@@ -395,7 +395,7 @@ export default createWidget("topic-timeline", {
     const stream = this.attrs.topic.get("postStream");
 
     // a little debounce to avoid flashing
-    setTimeout(() => {
+    Ember.run.later(() => {
       if (!this.state.position === pos) {
         return;
       }

GitHub

1 Like