From a0a0f6f37cbdd33f83f46b431b0108bfdb6fb753 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 18 Jul 2022 00:27:29 +0200 Subject: [PATCH] DEV: Run screen-track `run` in a runloop, drop jQ (#17545) --- .../javascripts/discourse/app/services/screen-track.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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();