DEV: Run screen-track `run` in a runloop, drop jQ (#17545)
This commit is contained in:
parent
fd9f8c6802
commit
a0a0f6f37c
|
@ -7,6 +7,7 @@ import {
|
||||||
resetHighestReadCache,
|
resetHighestReadCache,
|
||||||
setHighestReadCache,
|
setHighestReadCache,
|
||||||
} from "discourse/lib/topic-list-tracker";
|
} 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.
|
// We use this class to track how long posts in a topic are on the screen.
|
||||||
const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3;
|
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.
|
// Create an interval timer if we don't have one.
|
||||||
if (!this._interval) {
|
if (!this._interval) {
|
||||||
this._interval = setInterval(() => this.tick(), 1000);
|
this._interval = setInterval(() => {
|
||||||
$(window).on("scroll.screentrack", this.scrolled);
|
run(() => this.tick());
|
||||||
|
}, 1000);
|
||||||
|
window.addEventListener("scroll", this.scrolled);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._topicId = topicId;
|
this._topicId = topicId;
|
||||||
|
@ -60,7 +63,7 @@ export default class ScreenTrack extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).off("scroll.screentrack", this.scrolled);
|
window.removeEventListener("scroll", this.scrolled);
|
||||||
|
|
||||||
this.tick();
|
this.tick();
|
||||||
this.flush();
|
this.flush();
|
||||||
|
|
Loading…
Reference in New Issue