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