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

This commit is contained in:
Jarek Radosz 2022-07-18 00:27:29 +02:00 committed by GitHub
parent fd9f8c6802
commit a0a0f6f37c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();