REFACTOR: Remove Discourse constant from get-owner

This commit is contained in:
Robin Ward
2020-08-19 15:41:11 -04:00
parent 185ed80702
commit 347a4981a0
7 changed files with 68 additions and 38 deletions

View File

@@ -1,14 +1,20 @@
import deprecated from "discourse-common/lib/deprecated";
import { getOwner as emberGetOwner } from "@ember/application";
import { getOwner as emberGetOwner, setOwner } from "@ember/application";
let _default = {};
export function getOwner(obj) {
if (emberGetOwner) {
return emberGetOwner(obj) || Discourse.__container__;
return emberGetOwner(obj) || emberGetOwner(_default);
}
return obj.container;
}
export function setDefaultOwner(container) {
setOwner(_default, container);
}
// `this.container` is deprecated, but we can still build a container-like
// object for components to use
export function getRegister(obj) {

View File

@@ -82,6 +82,7 @@ const Singleton = Mixin.create({
resetCurrent(val) {
this._current = val;
return val;
}
});

View File

@@ -14,6 +14,7 @@ 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 {
name: "discourse-bootstrap",
@@ -23,6 +24,7 @@ export default {
setPluginContainer(container);
setURLContainer(container);
setModalContainer(container);
setDefaultOwner(container);
// Our test environment has its own bootstrap code
if (isTesting()) {