REFACTOR: Migrate `screenTrack` to a service

This commit is contained in:
Robin Ward 2020-08-14 12:42:05 -04:00
parent 86aa5d5e48
commit f52927cd33
7 changed files with 15 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import MountWidget from "discourse/components/mount-widget";
import { cloak, uncloak } from "discourse/widgets/post-stream";
import { isWorkaroundActive } from "discourse/lib/safari-hacks";
import offsetCalculator from "discourse/lib/offset-calculator";
import { inject as service } from "@ember/service";
function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
if (max < min) {
@ -26,6 +27,7 @@ function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
}
export default MountWidget.extend({
screenTrack: service(),
widget: "post-stream",
_topVisible: null,
_bottomVisible: null,

View File

@ -43,6 +43,9 @@ export function registerCustomPostMessageCallback(type, callback) {
export default Controller.extend(bufferedProperty("model"), {
composer: controller(),
application: controller(),
documentTitle: service(),
screenTrack: service(),
multiSelect: false,
selectedPostIds: null,
editingTopic: false,
@ -60,7 +63,6 @@ export default Controller.extend(bufferedProperty("model"), {
username_filters: null,
filter: null,
quoteState: null,
documentTitle: service(),
canRemoveTopicFeaturedLink: and(
"canEditTopicFeaturedLink",
@ -454,9 +456,7 @@ export default Controller.extend(bufferedProperty("model"), {
},
deferTopic() {
const screenTrack = Discourse.__container__.lookup("screen-track:main");
const currentUser = this.currentUser;
const topic = this.model;
const { screenTrack, currentUser, topic } = this;
screenTrack.reset();
screenTrack.stop();

View File

@ -9,7 +9,7 @@ export default {
name: "signup-cta",
initialize(container) {
const screenTrack = container.lookup("screen-track:main");
const screenTrack = container.lookup("service:screen-track");
const session = Session.current();
const siteSettings = container.lookup("site-settings:main");
const keyValueStore = container.lookup("key-value-store:main");

View File

@ -71,17 +71,14 @@ export default {
ALL_TARGETS.forEach(t => app.inject(t, "session", "session:main"));
app.inject("service", "session", "session:main");
// TODO: Automatically register this service
const screenTrack = new ScreenTrack(
topicTrackingState,
siteSettings,
session,
currentUser
);
app.register("screen-track:main", screenTrack, { instantiate: false });
["component", "route"].forEach(t =>
app.inject(t, "screenTrack", "screen-track:main")
);
app.register("service:screen-track", screenTrack, { instantiate: false });
if (currentUser) {
["component", "route", "controller", "service"].forEach(t => {

View File

@ -10,6 +10,7 @@ import { defaultHomepage } from "discourse/lib/utilities";
import Session from "discourse/models/session";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
import { inject as service } from "@ember/service";
// A helper to build a topic route for a filter
function filterQueryParams(params, defaultParams) {
@ -87,6 +88,7 @@ export default function(filter, extras) {
extras = extras || {};
return DiscourseRoute.extend(
{
screenTrack: service(),
queryParams,
beforeModel() {

View File

@ -5,12 +5,15 @@ import DiscourseRoute from "discourse/routes/discourse";
import DiscourseURL from "discourse/lib/url";
import { ID_CONSTRAINT } from "discourse/models/topic";
import { setTopicId } from "discourse/lib/topic-list-tracker";
import { inject as service } from "@ember/service";
const SCROLL_DELAY = 500;
import showModal from "discourse/lib/show-modal";
const TopicRoute = DiscourseRoute.extend({
screenTrack: service(),
init() {
this._super(...arguments);

View File

@ -14,6 +14,7 @@ moduleFor("controller:topic", "controller:topic", {
"service:document-title"
],
beforeEach() {
this.registry.register("service:screen-track", {}, { instantiate: false });
this.registry.injection("controller", "appEvents", "service:app-events");
}
});