DEV: Import `MessageBus` from `message-bus-client` instead of globals

This commit is contained in:
Robin Ward 2020-05-27 15:19:59 -04:00
parent 0f71d38d3a
commit 9dddbcc00d
9 changed files with 21 additions and 12 deletions

View File

@ -183,7 +183,7 @@ GEM
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
maxminddb (0.1.22) maxminddb (0.1.22)
memory_profiler (0.9.14) memory_profiler (0.9.14)
message_bus (3.2.0) message_bus (3.3.0)
rack (>= 1.1.3) rack (>= 1.1.3)
method_source (1.0.0) method_source (1.0.0)
mini_mime (1.0.2) mini_mime (1.0.2)

View File

@ -2,6 +2,7 @@ import I18n from "I18n";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import MessageBus from "message-bus-client";
const Backup = EmberObject.extend({ const Backup = EmberObject.extend({
destroy() { destroy() {
@ -11,7 +12,7 @@ const Backup = EmberObject.extend({
restore() { restore() {
return ajax("/admin/backups/" + this.filename + "/restore", { return ajax("/admin/backups/" + this.filename + "/restore", {
type: "POST", type: "POST",
data: { client_id: window.MessageBus.clientId } data: { client_id: MessageBus.clientId }
}); });
} }
}); });
@ -38,7 +39,7 @@ Backup.reopenClass({
type: "POST", type: "POST",
data: { data: {
with_uploads: withUploads, with_uploads: withUploads,
client_id: window.MessageBus.clientId client_id: MessageBus.clientId
} }
}).then(result => { }).then(result => {
if (!result.success) { if (!result.success) {

View File

@ -12,3 +12,7 @@ define("ember", ["exports"], function(__exports__) {
__exports__.default = Ember; __exports__.default = Ember;
}); });
define("message-bus-client", ["exports"], function(__exports__) {
__exports__.default = window.MessageBus;
});

View File

@ -9,6 +9,7 @@ import TopicTrackingState, {
import ScreenTrack from "discourse/lib/screen-track"; import ScreenTrack from "discourse/lib/screen-track";
import Site from "discourse/models/site"; import Site from "discourse/models/site";
import User from "discourse/models/user"; import User from "discourse/models/user";
import MessageBus from "message-bus-client";
const ALL_TARGETS = ["controller", "component", "route", "model", "adapter"]; const ALL_TARGETS = ["controller", "component", "route", "model", "adapter"];
@ -27,8 +28,7 @@ export default {
ALL_TARGETS.forEach(t => app.inject(t, "store", "service:store")); ALL_TARGETS.forEach(t => app.inject(t, "store", "service:store"));
} }
const messageBus = window.MessageBus; app.register("message-bus:main", MessageBus, { instantiate: false });
app.register("message-bus:main", messageBus, { instantiate: false });
ALL_TARGETS.concat("service").forEach(t => ALL_TARGETS.concat("service").forEach(t =>
app.inject(t, "messageBus", "message-bus:main") app.inject(t, "messageBus", "message-bus:main")
@ -39,7 +39,7 @@ export default {
app.currentUser = currentUser; app.currentUser = currentUser;
const topicTrackingState = TopicTrackingState.create({ const topicTrackingState = TopicTrackingState.create({
messageBus, messageBus: MessageBus,
currentUser currentUser
}); });
app.register("topic-tracking-state:main", topicTrackingState, { app.register("topic-tracking-state:main", topicTrackingState, {

View File

@ -3,4 +3,3 @@
//= require jquery //= require jquery
//= require ember_include //= require ember_include
//= require discourse-loader //= require discourse-loader
//= require ember-shim

View File

@ -29,3 +29,4 @@
//= require virtual-dom //= require virtual-dom
//= require virtual-dom-amd //= require virtual-dom-amd
//= require intersection-observer //= require intersection-observer
//= require discourse-shims

View File

@ -12,7 +12,7 @@
//= require ember-template-compiler //= require ember-template-compiler
//= require qunit/qunit/qunit //= require qunit/qunit/qunit
//= require ember-qunit //= require ember-qunit
//= require ember-shim //= require discourse-shims
//= require wizard-application //= require wizard-application
//= require wizard-vendor //= require wizard-vendor
//= require helpers/assertions //= require helpers/assertions

View File

@ -1,4 +1,6 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "helpers/qunit-helpers";
import MessageBus from "message-bus-client";
acceptance("Topic Discovery", { acceptance("Topic Discovery", {
settings: { settings: {
show_pinned_excerpt_desktop: true show_pinned_excerpt_desktop: true
@ -85,7 +87,7 @@ QUnit.test("Live update unread state", async assert => {
); );
// Mimic a messagebus message // Mimic a messagebus message
window.MessageBus.callbacks.filterBy("channel", "/latest").map(c => MessageBus.callbacks.filterBy("channel", "/latest").map(c =>
c.func({ c.func({
message_type: "read", message_type: "read",
topic_id: 11995, topic_id: 11995,

View File

@ -17,7 +17,7 @@
// Stuff we need to load first // Stuff we need to load first
//= require vendor //= require vendor
//= require ember-shim //= require discourse-shims
//= require pretty-text-bundle //= require pretty-text-bundle
//= require markdown-it-bundle //= require markdown-it-bundle
//= require application //= require application
@ -55,8 +55,10 @@ sinon.config = {
window.inTestEnv = true; window.inTestEnv = true;
let MessageBus = require("message-bus-client").default;
// Stop the message bus so we don't get ajax calls // Stop the message bus so we don't get ajax calls
window.MessageBus.stop(); MessageBus.stop();
// Trick JSHint into allow document.write // Trick JSHint into allow document.write
var d = document; var d = document;
@ -191,7 +193,7 @@ QUnit.testDone(function() {
window.Discourse.__container__ window.Discourse.__container__
); );
window.MessageBus.unsubscribe("*"); MessageBus.unsubscribe("*");
delete window.server; delete window.server;
window.Mousetrap.reset(); window.Mousetrap.reset();
}); });