Skip to content

A platform for community discussion. Free, open, simple.

DEV: Run screen-track `run` in a runloop, drop jQ (#17545)

Jarek Radosza0a0f6f37cbd
diff --git a/app/assets/javascripts/discourse/app/services/screen-track.js b/app/assets/javascripts/discourse/app/services/screen-track.js
index 0ada4ec67a5..edc9f9d3363 100644
--- a/app/assets/javascripts/discourse/app/services/screen-track.js
+++ b/app/assets/javascripts/discourse/app/services/screen-track.js
@@ -7,6 +7,7 @@ import {
resetHighestReadCache,
setHighestReadCache,
} from "discourse/lib/topic-list-tracker";
+import { run } from "@ember/runloop";
// We use this class to track how long posts in a topic are on the screen.
const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3;
@@ -46,8 +47,10 @@ export default class ScreenTrack extends Service {
// Create an interval timer if we don't have one.
if (!this._interval) {
- this._interval = setInterval(() => this.tick(), 1000);
- $(window).on("scroll.screentrack", this.scrolled);
+ this._interval = setInterval(() => {
+ run(() => this.tick());
+ }, 1000);
+ window.addEventListener("scroll", this.scrolled);
}
this._topicId = topicId;
@@ -60,7 +63,7 @@ export default class ScreenTrack extends Service {
return;
}
- $(window).off("scroll.screentrack", this.scrolled);
+ window.removeEventListener("scroll", this.scrolled);
this.tick();
this.flush();