REFACTOR: We can reuse `getOwner` for some container stuff
This commit is contained in:
parent
347a4981a0
commit
a3fb732b23
|
@ -5,7 +5,7 @@ let _default = {};
|
|||
|
||||
export function getOwner(obj) {
|
||||
if (emberGetOwner) {
|
||||
return emberGetOwner(obj) || emberGetOwner(_default);
|
||||
return emberGetOwner(obj || _default) || emberGetOwner(_default);
|
||||
}
|
||||
|
||||
return obj.container;
|
||||
|
|
|
@ -59,6 +59,7 @@ import { on } from "@ember/object/evented";
|
|||
import { addQuickAccessProfileItem } from "discourse/widgets/quick-access-profile";
|
||||
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
||||
import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
// If you add any methods to the API ensure you bump up this number
|
||||
const PLUGIN_API_VERSION = "0.10.2";
|
||||
|
@ -1200,17 +1201,11 @@ function cmpVersions(a, b) {
|
|||
return segmentsA.length - segmentsB.length;
|
||||
}
|
||||
|
||||
let _container;
|
||||
|
||||
export function setPluginContainer(container) {
|
||||
_container = container;
|
||||
}
|
||||
|
||||
function getPluginApi(version) {
|
||||
version = version.toString();
|
||||
if (cmpVersions(version, PLUGIN_API_VERSION) <= 0) {
|
||||
if (!_pluginv01) {
|
||||
_pluginv01 = new PluginApi(version, _container);
|
||||
_pluginv01 = new PluginApi(version, getOwner(this));
|
||||
}
|
||||
|
||||
// We are recycling the compatible object, but let's update to the higher version
|
||||
|
@ -1273,5 +1268,4 @@ function decorate(klass, evt, cb, id) {
|
|||
|
||||
export function resetPluginApi() {
|
||||
_pluginv01 = null;
|
||||
_container = null;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
import I18n from "I18n";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
let _container;
|
||||
export function setModalContainer(container) {
|
||||
_container = container;
|
||||
}
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
export default function(name, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
let container = getOwner(this);
|
||||
|
||||
// We use the container here because modals are like singletons
|
||||
// in Discourse. Only one can be shown with a particular state.
|
||||
const route = _container.lookup("route:application");
|
||||
const route = container.lookup("route:application");
|
||||
const modalController = route.controllerFor("modal");
|
||||
|
||||
modalController.set(
|
||||
|
@ -22,7 +20,7 @@ export default function(name, opts) {
|
|||
const controllerName = opts.admin ? `modals/${name}` : name;
|
||||
modalController.set("name", controllerName);
|
||||
|
||||
let controller = _container.lookup("controller:" + controllerName);
|
||||
let controller = container.lookup("controller:" + controllerName);
|
||||
const templateName = opts.templateName || dasherize(name);
|
||||
|
||||
const renderArgs = { into: "modal", outlet: "modalBody" };
|
||||
|
@ -31,7 +29,7 @@ export default function(name, opts) {
|
|||
} else {
|
||||
// use a basic controller
|
||||
renderArgs.controller = "basic-modal-body";
|
||||
controller = _container.lookup(`controller:${renderArgs.controller}`);
|
||||
controller = container.lookup(`controller:${renderArgs.controller}`);
|
||||
}
|
||||
|
||||
if (opts.addModalBodyView) {
|
||||
|
|
|
@ -11,9 +11,7 @@ import {
|
|||
import { setupURL, setupS3CDN } from "discourse-common/lib/get-url";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import { setIconList } from "discourse-common/lib/icon-library";
|
||||
import { setPluginContainer } from "discourse/lib/plugin-api";
|
||||
import { setURLContainer } from "discourse/lib/url";
|
||||
import { setModalContainer } from "discourse/lib/show-modal";
|
||||
import { setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
export default {
|
||||
|
@ -21,9 +19,7 @@ export default {
|
|||
|
||||
// The very first initializer to run
|
||||
initialize(container, app) {
|
||||
setPluginContainer(container);
|
||||
setURLContainer(container);
|
||||
setModalContainer(container);
|
||||
setDefaultOwner(container);
|
||||
|
||||
// Our test environment has its own bootstrap code
|
||||
|
|
|
@ -5,7 +5,7 @@ import { later } from "@ember/runloop";
|
|||
import sessionFixtures from "fixtures/session-fixtures";
|
||||
import HeaderComponent from "discourse/components/site-header";
|
||||
import { forceMobile, resetMobile } from "discourse/lib/mobile";
|
||||
import { resetPluginApi, setPluginContainer } from "discourse/lib/plugin-api";
|
||||
import { resetPluginApi } from "discourse/lib/plugin-api";
|
||||
import {
|
||||
clearCache as clearOutletCache,
|
||||
resetExtraClasses
|
||||
|
@ -29,7 +29,6 @@ import { currentSettings, mergeSettings } from "helpers/site-settings";
|
|||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
||||
import { setURLContainer } from "discourse/lib/url";
|
||||
import { setModalContainer } from "discourse/lib/show-modal";
|
||||
import { setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
export function currentUser() {
|
||||
|
@ -173,9 +172,7 @@ export function acceptance(name, options) {
|
|||
|
||||
Discourse.reset();
|
||||
this.container = getOwner(this);
|
||||
setPluginContainer(this.container);
|
||||
setURLContainer(this.container);
|
||||
setModalContainer(this.container);
|
||||
setDefaultOwner(this.container);
|
||||
|
||||
if (options.site) {
|
||||
|
@ -211,7 +208,6 @@ export function acceptance(name, options) {
|
|||
setTopicList(null);
|
||||
_clearSnapshots();
|
||||
setURLContainer(null);
|
||||
setModalContainer(null);
|
||||
setDefaultOwner(null);
|
||||
Discourse._runInitializer(
|
||||
"instanceInitializers",
|
||||
|
|
Loading…
Reference in New Issue