REFACTOR: Move app-events:main to service:app-events (#8152)

AppEvents was always a service object in disguise, so we should move it
to the correct place in the application. Doing this allows other service
objects to inject it easily without container access.

In the future we should also deprecate `this.appEvents` without an
explicit injection too.
This commit is contained in:
Robin Ward
2019-10-04 10:06:08 -04:00
committed by GitHub
parent 5e88baebb6
commit f5d391a48a
20 changed files with 41 additions and 35 deletions

View File

@@ -704,7 +704,7 @@ testCase("replace-text event by default", async function(assert) {
this.set("value", "red green blue");
await this.container
.lookup("app-events:main")
.lookup("service:app-events")
.trigger("composer:replace-text", "green", "yellow");
assert.equal(this.value, "red green blue");
@@ -714,7 +714,7 @@ composerTestCase("replace-text event for composer", async function(assert) {
this.set("value", "red green blue");
await this.container
.lookup("app-events:main")
.lookup("service:app-events")
.trigger("composer:replace-text", "green", "yellow");
assert.equal(this.value, "red yellow blue");
@@ -800,7 +800,7 @@ composerTestCase("replace-text event for composer", async function(assert) {
setTextareaSelection(textarea, start, start + len);
this.container
.lookup("app-events:main")
.lookup("service:app-events")
.trigger("composer:replace-text", "green", "yellow", { forceFocus: true });
Ember.run.next(() => {

View File

@@ -1,15 +1,15 @@
import AppEvents from "discourse/lib/app-events";
import Topic from "discourse/models/topic";
import PostStream from "discourse/models/post-stream";
import { Placeholder } from "discourse/lib/posts-with-placeholders";
moduleFor("controller:topic", "controller:topic", {
needs: ["controller:composer", "controller:application"],
needs: [
"controller:composer",
"controller:application",
"service:app-events"
],
beforeEach() {
this.registry.register("app-events:main", AppEvents.create(), {
instantiate: false
});
this.registry.injection("controller", "appEvents", "app-events:main");
this.registry.injection("controller", "appEvents", "service:app-events");
}
});

View File

@@ -1,4 +1,3 @@
import AppEvents from "discourse/lib/app-events";
import createStore from "helpers/create-store";
import { autoLoadModules } from "discourse/initializers/auto-load-modules";
import TopicTrackingState from "discourse/models/topic-tracking-state";
@@ -11,19 +10,15 @@ export default function(name, opts) {
}
test(name, function(assert) {
const appEvents = AppEvents.create();
this.site = Discourse.Site.current();
this.registry.register("site-settings:main", Discourse.SiteSettings, {
instantiate: false
});
this.registry.register("app-events:main", appEvents, {
instantiate: false
});
this.registry.register("capabilities:main", Ember.Object);
this.registry.register("site:main", this.site, { instantiate: false });
this.registry.injection("component", "siteSettings", "site-settings:main");
this.registry.injection("component", "appEvents", "app-events:main");
this.registry.injection("component", "appEvents", "service:app-events");
this.registry.injection("component", "capabilities", "capabilities:main");
this.registry.injection("component", "site", "site:main");

View File

@@ -1,5 +1,5 @@
import { currentUser } from "helpers/qunit-helpers";
import AppEvents from "discourse/lib/app-events";
import AppEvents from "discourse/services/app-events";
import Composer from "discourse/models/composer";
import createStore from "helpers/create-store";

View File

@@ -159,7 +159,7 @@ QUnit.testDone(function() {
// ensures any event not removed is not leaking between tests
// most likely in intialisers, other places (controller, component...)
// should be fixed in code
var appEvents = window.Discourse.__container__.lookup("app-events:main");
var appEvents = window.Discourse.__container__.lookup("service:app-events");
var events = appEvents.__proto__._events;
Object.keys(events).forEach(function(eventKey) {
var event = events[eventKey];