REFACTOR: Don't use container in Scrolling mixin

This commit is contained in:
Robin Ward 2020-08-14 12:30:06 -04:00
parent 37c6fef535
commit 99764d8108

View File

@ -1,6 +1,7 @@
import { scheduleOnce } from "@ember/runloop"; import { scheduleOnce } from "@ember/runloop";
import discourseDebounce from "discourse/lib/debounce"; import discourseDebounce from "discourse/lib/debounce";
import Mixin from "@ember/object/mixin"; import Mixin from "@ember/object/mixin";
import { inject as service } from "@ember/service";
/** /**
This object provides the DOM methods we need for our Mixin to bind to scrolling This object provides the DOM methods we need for our Mixin to bind to scrolling
@ -26,17 +27,18 @@ const ScrollingDOMMethods = {
}; };
const Scrolling = Mixin.create({ const Scrolling = Mixin.create({
router: service(),
// Begin watching for scroll events. By default they will be called at max every 100ms. // Begin watching for scroll events. By default they will be called at max every 100ms.
// call with {debounce: N} for a diff time // call with {debounce: N} for a diff time
bindScrolling(opts) { bindScrolling(opts) {
opts = opts || { debounce: 100 }; opts = opts || { debounce: 100 };
// So we can not call the scrolled event while transitioning // So we can not call the scrolled event while transitioning. There is no public API for this :'(
const router = Discourse.__container__.lookup("router:main") const microLib = this.router._router._routerMicrolib;
._routerMicrolib;
let onScrollMethod = () => { let onScrollMethod = () => {
if (router.activeTransition) { if (microLib.activeTransition) {
return; return;
} }
return scheduleOnce("afterRender", this, "scrolled"); return scheduleOnce("afterRender", this, "scrolled");