mirror of
https://github.com/discourse/discourse.git
synced 2025-08-17 18:04:11 +08:00
DEV: Reduce the getOwnerWithFallback
usage (#34330)
This commit is contained in:
parent
e94b255133
commit
07425a9fed
5 changed files with 25 additions and 29 deletions
|
@ -1,11 +1,11 @@
|
|||
import { action } from "@ember/object";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { service } from "@ember/service";
|
||||
import KeyboardShortcutsHelp from "discourse/components/modal/keyboard-shortcuts-help";
|
||||
import NotActivatedModal from "discourse/components/modal/not-activated";
|
||||
import { RouteException } from "discourse/controllers/exception";
|
||||
import { setting } from "discourse/lib/computed";
|
||||
import deprecated from "discourse/lib/deprecated";
|
||||
import { getOwnerWithFallback } from "discourse/lib/get-owner";
|
||||
import getURL from "discourse/lib/get-url";
|
||||
import logout from "discourse/lib/logout";
|
||||
import mobile from "discourse/lib/mobile";
|
||||
|
@ -176,16 +176,22 @@ export default class ApplicationRoute extends DiscourseRoute {
|
|||
showLogin(props = {}) {
|
||||
const t = this.router.transitionTo("login");
|
||||
t.wantsTo = true;
|
||||
const controller = getOwnerWithFallback(this).lookup("controller:login");
|
||||
return t.then(() => controller.setProperties({ ...props }));
|
||||
return t.then(() =>
|
||||
getOwner(this)
|
||||
.lookup("controller:login")
|
||||
.setProperties({ ...props })
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
showCreateAccount(props = {}) {
|
||||
const t = this.router.transitionTo("signup");
|
||||
t.wantsTo = true;
|
||||
const controller = getOwnerWithFallback(this).lookup("controller:signup");
|
||||
return t.then(() => controller.setProperties({ ...props }));
|
||||
return t.then(() =>
|
||||
getOwner(this)
|
||||
.lookup("controller:signup")
|
||||
.setProperties({ ...props })
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -225,7 +231,7 @@ export default class ApplicationRoute extends DiscourseRoute {
|
|||
"createNewTopicViaParam on the application route is deprecated. Use the composer service instead",
|
||||
{ id: "discourse.createNewTopicViaParams" }
|
||||
);
|
||||
getOwnerWithFallback(this).lookup("service:composer").openNewTopic({
|
||||
this.composer.openNewTopic({
|
||||
title,
|
||||
body,
|
||||
categoryId,
|
||||
|
@ -244,7 +250,7 @@ export default class ApplicationRoute extends DiscourseRoute {
|
|||
"createNewMessageViaParams on the application route is deprecated. Use the composer service instead",
|
||||
{ id: "discourse.createNewMessageViaParams" }
|
||||
);
|
||||
getOwnerWithFallback(this).lookup("service:composer").openNewMessage({
|
||||
this.composer.openNewMessage({
|
||||
recipients,
|
||||
title: topicTitle,
|
||||
body: topicBody,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { tracked } from "@glimmer/tracking";
|
||||
import EmberObject, { action, computed } from "@ember/object";
|
||||
import { alias, and, or, reads } from "@ember/object/computed";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { cancel, next, scheduleOnce } from "@ember/runloop";
|
||||
import Service, { service } from "@ember/service";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
|
@ -24,7 +25,6 @@ import prepareFormTemplateData, {
|
|||
getFormTemplateObject,
|
||||
} from "discourse/lib/form-template-validation";
|
||||
import { shortDate } from "discourse/lib/formatter";
|
||||
import { getOwnerWithFallback } from "discourse/lib/get-owner";
|
||||
import getURL from "discourse/lib/get-url";
|
||||
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
||||
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||
|
@ -137,7 +137,7 @@ export default class ComposerService extends Service {
|
|||
@or("replyingToWhisper", "model.whisper") isWhispering;
|
||||
|
||||
get topicController() {
|
||||
return getOwnerWithFallback(this).lookup("controller:topic");
|
||||
return getOwner(this).lookup("controller:topic");
|
||||
}
|
||||
|
||||
get isPreviewVisible() {
|
||||
|
@ -275,10 +275,7 @@ export default class ComposerService extends Service {
|
|||
|
||||
@computed
|
||||
get showToolbar() {
|
||||
const keyValueStore = getOwnerWithFallback(this).lookup(
|
||||
"service:key-value-store"
|
||||
);
|
||||
const storedVal = keyValueStore.get("toolbar-enabled");
|
||||
const storedVal = this.keyValueStore.get("toolbar-enabled");
|
||||
if (this._toolbarEnabled === undefined && storedVal === undefined) {
|
||||
// iPhone 6 is 375, anything narrower and toolbar should
|
||||
// be default disabled.
|
||||
|
@ -290,11 +287,8 @@ export default class ComposerService extends Service {
|
|||
}
|
||||
|
||||
set showToolbar(val) {
|
||||
const keyValueStore = getOwnerWithFallback(this).lookup(
|
||||
"service:key-value-store"
|
||||
);
|
||||
this._toolbarEnabled = val;
|
||||
keyValueStore.set({
|
||||
this.keyValueStore.set({
|
||||
key: "toolbar-enabled",
|
||||
value: val ? "true" : "false",
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { tracked } from "@glimmer/tracking";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import { render, settled } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
|
@ -6,7 +7,6 @@ import curryComponent from "ember-curry-component";
|
|||
import { module, test } from "qunit";
|
||||
import DecoratedHtml from "discourse/components/decorated-html";
|
||||
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
||||
import { getOwnerWithFallback } from "discourse/lib/get-owner";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { POST_STREAM_DEPRECATION_OPTIONS } from "discourse/widgets/widget";
|
||||
|
||||
|
@ -68,7 +68,7 @@ module("Integration | Component | <DecoratedHtml />", function (hooks) {
|
|||
<div id="render-glimmer">Hello from {{@value}} Component</div>
|
||||
</template>,
|
||||
{ value: "Curried" },
|
||||
getOwnerWithFallback(this)
|
||||
getOwner(this)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@ import { service } from "@ember/service";
|
|||
import EmojiPickerDetached from "discourse/components/emoji-picker/detached";
|
||||
import { bind } from "discourse/lib/decorators";
|
||||
import { number } from "discourse/lib/formatter";
|
||||
import { getOwnerWithFallback } from "discourse/lib/get-owner";
|
||||
import { replaceIcon } from "discourse/lib/icon-library";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { i18n } from "discourse-i18n";
|
||||
|
@ -121,9 +120,7 @@ class ChatSetupInit {
|
|||
// we want to decorate the chat quote dates regardless
|
||||
// of whether the current user has chat enabled
|
||||
api.decorateCookedElement((elem) => {
|
||||
const currentUser = getOwnerWithFallback(this).lookup(
|
||||
"service:current-user"
|
||||
);
|
||||
const currentUser = owner.lookup("service:current-user");
|
||||
const currentUserTimezone = currentUser?.user_option?.timezone;
|
||||
const chatTranscriptElements =
|
||||
elem.querySelectorAll(".chat-transcript");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { getOwnerWithFallback } from "discourse/lib/get-owner";
|
||||
import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import extractVariablesFromChatChannel from "../../lib/variables-chat-channel";
|
||||
|
@ -84,10 +83,10 @@ function addChatIntegration(api, container) {
|
|||
}
|
||||
|
||||
const channelVariablesExtractor = function () {
|
||||
const chat = getOwnerWithFallback(this).lookup("service:chat");
|
||||
const chat = container.lookup("service:chat");
|
||||
const activeChannel = chat?.activeChannel;
|
||||
const currentMessage = activeChannel?.draft;
|
||||
const router = getOwnerWithFallback(this).lookup("service:router");
|
||||
const router = container.lookup("service:router");
|
||||
|
||||
return extractVariablesFromChatChannel(
|
||||
activeChannel,
|
||||
|
@ -97,10 +96,10 @@ function addChatIntegration(api, container) {
|
|||
};
|
||||
|
||||
const threadVariablesExtractor = function () {
|
||||
const chat = getOwnerWithFallback(this).lookup("service:chat");
|
||||
const chat = container.lookup("service:chat");
|
||||
const activeThread = chat?.activeChannel?.activeThread;
|
||||
const currentMessage = activeThread?.draft;
|
||||
const router = getOwnerWithFallback(this).lookup("service:router");
|
||||
const router = container.lookup("service:router");
|
||||
|
||||
return extractVariablesFromChatThread(activeThread, currentMessage, router);
|
||||
};
|
||||
|
@ -126,7 +125,7 @@ function addChatIntegration(api, container) {
|
|||
|
||||
const textarea = this.composer?.textarea?.textarea; // this.composer.textarea is a TextareaInteractor instance
|
||||
|
||||
getOwnerWithFallback(this)
|
||||
container
|
||||
.lookup("service:d-templates")
|
||||
.showTextAreaUI(contextVariablesExtractor, textarea);
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue