mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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(() => {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user