From 548403016299860dad54c5f3cc116c1d4c20e41b Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 25 Sep 2023 19:30:07 +0200 Subject: [PATCH] DEV: Use `disableImplicitInjections` more extensively (#23579) --- .../javascripts/discourse/app/services/composer.js | 14 ++++++++++---- .../discourse/app/services/key-value-store.js | 2 ++ .../javascripts/discourse/app/services/lightbox.js | 4 +++- .../app/services/media-optimization-worker.js | 9 ++++++--- .../discourse/app/services/message-bus.js | 2 ++ .../services/more-topics-preference-tracking.js | 2 ++ .../discourse/app/services/navigation-menu.js | 2 ++ .../discourse/app/services/network-connectivity.js | 2 ++ .../discourse/app/services/route-scroll-manager.js | 2 ++ .../discourse/app/services/screen-track.js | 7 +++++++ .../discourse/app/services/sidebar-state.js | 3 ++- .../discourse/app/services/site-settings.js | 2 ++ .../discourse/app/services/user-status.js | 4 +++- .../discourse/app/services/user-tips.js | 2 ++ 14 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.js index 6d711a44a5a..89bb24eca9c 100644 --- a/app/assets/javascripts/discourse/app/services/composer.js +++ b/app/assets/javascripts/discourse/app/services/composer.js @@ -39,6 +39,7 @@ import { iconHTML } from "discourse-common/lib/icon-library"; import prepareFormTemplateData from "discourse/lib/form-template-validation"; import DiscardDraftModal from "discourse/components/modal/discard-draft"; import PostEnqueuedModal from "discourse/components/modal/post-enqueued"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; async function loadDraft(store, opts = {}) { let { draft, draftKey, draftSequence } = opts; @@ -99,14 +100,19 @@ export function addComposerSaveErrorCallback(callback) { _composerSaveErrorCallbacks.push(callback); } +@disableImplicitInjections export default class ComposerService extends Service { - @service router; - @service dialog; - @service site; - @service store; @service appEvents; @service capabilities; + @service currentUser; + @service dialog; + @service keyValueStore; + @service messageBus; @service modal; + @service router; + @service site; + @service siteSettings; + @service store; checkedMessages = false; messageCount = null; diff --git a/app/assets/javascripts/discourse/app/services/key-value-store.js b/app/assets/javascripts/discourse/app/services/key-value-store.js index 91d9e0f12f6..2378f4119f0 100644 --- a/app/assets/javascripts/discourse/app/services/key-value-store.js +++ b/app/assets/javascripts/discourse/app/services/key-value-store.js @@ -1,5 +1,6 @@ import Service from "@ember/service"; import KeyValueStore from "discourse/lib/key-value-store"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const PROXIED_METHODS = Object.getOwnPropertyNames( KeyValueStore.prototype @@ -10,6 +11,7 @@ const PROXIED_METHODS = Object.getOwnPropertyNames( * Alternatively, consumers can use `discourse/lib/key-value-store` directly * to create their own namespaced store. * */ +@disableImplicitInjections export default class KeyValueStoreService extends Service { _keyValueStore = new KeyValueStore("discourse_"); diff --git a/app/assets/javascripts/discourse/app/services/lightbox.js b/app/assets/javascripts/discourse/app/services/lightbox.js index 45913186927..b8e7d6ed5b2 100644 --- a/app/assets/javascripts/discourse/app/services/lightbox.js +++ b/app/assets/javascripts/discourse/app/services/lightbox.js @@ -9,14 +9,16 @@ import { getSiteThemeColor, setSiteThemeColor, } from "discourse/lib/lightbox/helpers"; - import { bind } from "discourse-common/utils/decorators"; import { isDocumentRTL } from "discourse/lib/text-direction"; import { processHTML } from "discourse/lib/lightbox/process-html"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; +@disableImplicitInjections export default class LightboxService extends Service { @service appEvents; @service site; + @service siteSettings; lightboxIsOpen = false; lightboxClickElements = []; diff --git a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js index 12873d7c87f..0b6859e5cee 100644 --- a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js +++ b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js @@ -1,8 +1,8 @@ -import Service from "@ember/service"; -import { getOwner } from "@ember/application"; +import Service, { inject as service } from "@ember/service"; import { Promise } from "rsvp"; import { fileToImageData } from "discourse/lib/media-optimization-utils"; import { getAbsoluteURL, getURLWithCDN } from "discourse-common/lib/get-url"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; /** * This worker follows a particular promise/callback flow to ensure @@ -20,8 +20,11 @@ import { getAbsoluteURL, getURLWithCDN } from "discourse-common/lib/get-url"; * will wait for the "installed" message to be handled before continuing * with any image optimization work. */ +@disableImplicitInjections export default class MediaOptimizationWorkerService extends Service { - appEvents = getOwner(this).lookup("service:app-events"); + @service appEvents; + @service siteSettings; + worker = null; workerUrl = getAbsoluteURL("/javascripts/media-optimization-worker.js"); currentComposerUploadData = null; diff --git a/app/assets/javascripts/discourse/app/services/message-bus.js b/app/assets/javascripts/discourse/app/services/message-bus.js index dd112640be6..1fa1de73337 100644 --- a/app/assets/javascripts/discourse/app/services/message-bus.js +++ b/app/assets/javascripts/discourse/app/services/message-bus.js @@ -1,5 +1,7 @@ import MessageBus from "message-bus-client"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; +@disableImplicitInjections export default class MessageBusService { static isServiceFactory = true; diff --git a/app/assets/javascripts/discourse/app/services/more-topics-preference-tracking.js b/app/assets/javascripts/discourse/app/services/more-topics-preference-tracking.js index 4359f927f09..c239cb184c0 100644 --- a/app/assets/javascripts/discourse/app/services/more-topics-preference-tracking.js +++ b/app/assets/javascripts/discourse/app/services/more-topics-preference-tracking.js @@ -1,8 +1,10 @@ import Service, { inject as service } from "@ember/service"; import { tracked } from "@glimmer/tracking"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const TOPIC_LIST_PREFERENCE_KEY = "more-topics-list-preference"; +@disableImplicitInjections export default class MoreTopicsPreferenceTracking extends Service { @service keyValueStore; diff --git a/app/assets/javascripts/discourse/app/services/navigation-menu.js b/app/assets/javascripts/discourse/app/services/navigation-menu.js index 848356bf075..3eee65a9a91 100644 --- a/app/assets/javascripts/discourse/app/services/navigation-menu.js +++ b/app/assets/javascripts/discourse/app/services/navigation-menu.js @@ -1,5 +1,7 @@ import Service, { inject as service } from "@ember/service"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; +@disableImplicitInjections export default class NavigationMenu extends Service { @service site; @service siteSettings; diff --git a/app/assets/javascripts/discourse/app/services/network-connectivity.js b/app/assets/javascripts/discourse/app/services/network-connectivity.js index 9e1b9683203..7b924286f0e 100644 --- a/app/assets/javascripts/discourse/app/services/network-connectivity.js +++ b/app/assets/javascripts/discourse/app/services/network-connectivity.js @@ -4,9 +4,11 @@ import { ajax } from "discourse/lib/ajax"; import { bind } from "discourse-common/utils/decorators"; import { cancel } from "@ember/runloop"; import { tracked } from "@glimmer/tracking"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const CONNECTIVITY_ERROR_CLASS = "network-disconnected"; +@disableImplicitInjections export default class NetworkConnectivity extends Service { @tracked connected = true; diff --git a/app/assets/javascripts/discourse/app/services/route-scroll-manager.js b/app/assets/javascripts/discourse/app/services/route-scroll-manager.js index 0de8c012912..1e3386d2636 100644 --- a/app/assets/javascripts/discourse/app/services/route-scroll-manager.js +++ b/app/assets/javascripts/discourse/app/services/route-scroll-manager.js @@ -2,6 +2,7 @@ import Service, { inject as service } from "@ember/service"; import { bind } from "discourse-common/utils/decorators"; import { schedule } from "@ember/runloop"; import { isTesting } from "discourse-common/config/environment"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const MAX_SCROLL_LOCATIONS = 100; @@ -14,6 +15,7 @@ const MAX_SCROLL_LOCATIONS = 100; * To opt-out of the behaviour, individual routes can add a scrollOnTransition * boolean to their RouteInfo metadata using Ember's `buildRouteInfoMetadata` hook. */ +@disableImplicitInjections export default class RouteScrollManager extends Service { @service router; diff --git a/app/assets/javascripts/discourse/app/services/screen-track.js b/app/assets/javascripts/discourse/app/services/screen-track.js index c6a0294ac76..d8e35112a13 100644 --- a/app/assets/javascripts/discourse/app/services/screen-track.js +++ b/app/assets/javascripts/discourse/app/services/screen-track.js @@ -8,6 +8,7 @@ import { setHighestReadCache, } from "discourse/lib/topic-list-tracker"; import { run } from "@ember/runloop"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; // We use this class to track how long posts in a topic are on the screen. const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3; @@ -17,8 +18,14 @@ const ANON_MAX_TOPIC_IDS = 5; const AJAX_FAILURE_DELAYS = [5000, 10000, 20000, 40000]; const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504]; +@disableImplicitInjections export default class ScreenTrack extends Service { @service appEvents; + @service currentUser; + @service keyValueStore; + @service session; + @service siteSettings; + @service topicTrackingState; _consolidatedTimings = []; _lastTick = null; diff --git a/app/assets/javascripts/discourse/app/services/sidebar-state.js b/app/assets/javascripts/discourse/app/services/sidebar-state.js index 9f71d131373..208c8d2b05f 100644 --- a/app/assets/javascripts/discourse/app/services/sidebar-state.js +++ b/app/assets/javascripts/discourse/app/services/sidebar-state.js @@ -1,15 +1,16 @@ import Service from "@ember/service"; import { tracked } from "@glimmer/tracking"; - import { currentPanelKey, customPanels as panels, } from "discourse/lib/sidebar/custom-sections"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const COMBINED_MODE = "combined"; const SEPARATED_MODE = "separated"; const MAIN_PANEL = "main"; +@disableImplicitInjections export default class SidebarState extends Service { @tracked currentPanelKey = currentPanelKey; @tracked panels = panels; diff --git a/app/assets/javascripts/discourse/app/services/site-settings.js b/app/assets/javascripts/discourse/app/services/site-settings.js index e57c90719c0..f9414ae8f3e 100644 --- a/app/assets/javascripts/discourse/app/services/site-settings.js +++ b/app/assets/javascripts/discourse/app/services/site-settings.js @@ -1,6 +1,8 @@ import PreloadStore from "discourse/lib/preload-store"; import { TrackedObject } from "@ember-compat/tracked-built-ins"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; +@disableImplicitInjections export default class SiteSettingsService { static isServiceFactory = true; diff --git a/app/assets/javascripts/discourse/app/services/user-status.js b/app/assets/javascripts/discourse/app/services/user-status.js index 90370fe0020..475a7d3582a 100644 --- a/app/assets/javascripts/discourse/app/services/user-status.js +++ b/app/assets/javascripts/discourse/app/services/user-status.js @@ -1,9 +1,11 @@ import Service, { inject as service } from "@ember/service"; import { ajax } from "discourse/lib/ajax"; import DoNotDisturb from "discourse/lib/do-not-disturb"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; +@disableImplicitInjections export default class UserStatusService extends Service { - @service appEvents; + @service currentUser; async set(status, pauseNotifications) { await ajax({ diff --git a/app/assets/javascripts/discourse/app/services/user-tips.js b/app/assets/javascripts/discourse/app/services/user-tips.js index 9de6f7e8b8d..09b09e8a1e9 100644 --- a/app/assets/javascripts/discourse/app/services/user-tips.js +++ b/app/assets/javascripts/discourse/app/services/user-tips.js @@ -7,9 +7,11 @@ import tippy from "tippy.js"; import isElementInViewport from "discourse/lib/is-element-in-viewport"; import discourseLater from "discourse-common/lib/later"; import { cancel } from "@ember/runloop"; +import { disableImplicitInjections } from "discourse/lib/implicit-injections"; const TIPPY_DELAY = 500; +@disableImplicitInjections export default class UserTips extends Service { #instances = new Map();