mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 18:05:37 +08:00
FIX: prevents appEvents to leak (#7714)
This commit is contained in:
parent
84e5d58a0d
commit
c462c2f271
|
@ -35,7 +35,32 @@ export default Ember.Component.extend({
|
|||
}
|
||||
});
|
||||
|
||||
this.appEvents.on("modal:body-shown", data => {
|
||||
this.appEvents.on("modal:body-shown", this, "_modalBodyShown");
|
||||
},
|
||||
|
||||
@on("willDestroyElement")
|
||||
cleanUp() {
|
||||
$("html").off("keydown.discourse-modal");
|
||||
this.appEvents.off("modal:body-shown", this, "_modalBodyShown");
|
||||
},
|
||||
|
||||
mouseDown(e) {
|
||||
if (!this.dismissable) {
|
||||
return;
|
||||
}
|
||||
const $target = $(e.target);
|
||||
if (
|
||||
$target.hasClass("modal-middle-container") ||
|
||||
$target.hasClass("modal-outer-container")
|
||||
) {
|
||||
// Delegate click to modal close if clicked outside.
|
||||
// We do this because some CSS of ours seems to cover
|
||||
// the backdrop and makes it unclickable.
|
||||
$(".modal-header a.close").click();
|
||||
}
|
||||
},
|
||||
|
||||
_modalBodyShown(data) {
|
||||
if (this.isDestroying || this.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
@ -65,27 +90,5 @@ export default Ember.Component.extend({
|
|||
} else {
|
||||
this.set("dismissable", true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@on("willDestroyElement")
|
||||
cleanUp() {
|
||||
$("html").off("keydown.discourse-modal");
|
||||
},
|
||||
|
||||
mouseDown(e) {
|
||||
if (!this.dismissable) {
|
||||
return;
|
||||
}
|
||||
const $target = $(e.target);
|
||||
if (
|
||||
$target.hasClass("modal-middle-container") ||
|
||||
$target.hasClass("modal-outer-container")
|
||||
) {
|
||||
// Delegate click to modal close if clicked outside.
|
||||
// We do this because some CSS of ours seems to cover
|
||||
// the backdrop and makes it unclickable.
|
||||
$(".modal-header a.close").click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -61,7 +61,7 @@ export default Ember.Component.extend({
|
|||
willDestroyElement() {
|
||||
this._dispatched.forEach(evt => {
|
||||
const [eventName, caller] = evt;
|
||||
this.appEvents.off(eventName, caller);
|
||||
this.appEvents.off(eventName, this, caller);
|
||||
});
|
||||
Ember.run.cancel(this._timeout);
|
||||
},
|
||||
|
@ -84,7 +84,7 @@ export default Ember.Component.extend({
|
|||
const caller = refreshArg =>
|
||||
this.eventDispatched(eventName, key, refreshArg);
|
||||
this._dispatched.push([eventName, caller]);
|
||||
this.appEvents.on(eventName, caller);
|
||||
this.appEvents.on(eventName, this, caller);
|
||||
},
|
||||
|
||||
queueRerender(callback) {
|
||||
|
|
|
@ -108,7 +108,22 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
|
|||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.appEvents.on("post:show-revision", (postNumber, revision) => {
|
||||
|
||||
this.appEvents.on("post:show-revision", this, "_showRevision");
|
||||
|
||||
this.setProperties({
|
||||
selectedPostIds: [],
|
||||
quoteState: new QuoteState()
|
||||
});
|
||||
},
|
||||
|
||||
willDestroy() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.appEvents.off("post:show-revision", this, "_showRevision");
|
||||
},
|
||||
|
||||
_showRevision(postNumber, revision) {
|
||||
const post = this.model.get("postStream").postForPostNumber(postNumber);
|
||||
if (!post) {
|
||||
return;
|
||||
|
@ -117,11 +132,6 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
|
|||
Ember.run.scheduleOnce("afterRender", () => {
|
||||
this.send("showHistory", post, revision);
|
||||
});
|
||||
});
|
||||
this.setProperties({
|
||||
selectedPostIds: [],
|
||||
quoteState: new QuoteState()
|
||||
});
|
||||
},
|
||||
|
||||
showCategoryChooser: Ember.computed.not("model.isPrivateMessage"),
|
||||
|
|
|
@ -5,27 +5,32 @@ export default {
|
|||
name: "avatar-select",
|
||||
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup("site-settings:main");
|
||||
const appEvents = container.lookup("app-events:main");
|
||||
this.selectAvatarsEnabled = container.lookup(
|
||||
"site-settings:main"
|
||||
).select_avatars_enabled;
|
||||
|
||||
appEvents.on("show-avatar-select", user => {
|
||||
const avatarTemplate = user.get("avatar_template");
|
||||
container
|
||||
.lookup("app-events:main")
|
||||
.on("show-avatar-select", this, "_showAvatarSelect");
|
||||
},
|
||||
|
||||
_showAvatarSelect(user) {
|
||||
const avatarTemplate = user.avatar_template;
|
||||
let selected = "uploaded";
|
||||
|
||||
if (avatarTemplate === user.get("system_avatar_template")) {
|
||||
if (avatarTemplate === user.system_avatar_template) {
|
||||
selected = "system";
|
||||
} else if (avatarTemplate === user.get("gravatar_avatar_template")) {
|
||||
} else if (avatarTemplate === user.gravatar_avatar_template) {
|
||||
selected = "gravatar";
|
||||
}
|
||||
|
||||
const modal = showModal("avatar-selector");
|
||||
modal.setProperties({ user, selected });
|
||||
|
||||
if (siteSettings.selectable_avatars_enabled) {
|
||||
if (this.selectAvatarsEnabled) {
|
||||
ajax("/site/selectable-avatars.json").then(avatars =>
|
||||
modal.set("selectableAvatars", avatars)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,16 +4,20 @@ export default {
|
|||
after: "message-bus",
|
||||
|
||||
initialize(container) {
|
||||
const appEvents = container.lookup("app-events:main");
|
||||
const user = container.lookup("current-user:main");
|
||||
|
||||
if (!user) return; // must be logged in
|
||||
if (!window.ExperimentalBadge) return; // must have the Badging API
|
||||
|
||||
appEvents.on("notifications:changed", () => {
|
||||
let notifications =
|
||||
user.get("unread_notifications") + user.get("unread_private_messages");
|
||||
window.ExperimentalBadge.set(notifications);
|
||||
});
|
||||
const user = container.lookup("current-user:main");
|
||||
if (!user) return; // must be logged in
|
||||
|
||||
this.notifications =
|
||||
user.unread_notifications + user.unread_private_messages;
|
||||
|
||||
container
|
||||
.lookup("app-events:main")
|
||||
.on("notifications:changed", this, "_updateBadge");
|
||||
},
|
||||
|
||||
_updateBadge() {
|
||||
window.ExperimentalBadge.set(this.notifications);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,16 +3,18 @@ export default {
|
|||
after: "message-bus",
|
||||
|
||||
initialize(container) {
|
||||
const appEvents = container.lookup("app-events:main");
|
||||
const user = container.lookup("current-user:main");
|
||||
|
||||
if (!user) return; // must be logged in
|
||||
|
||||
appEvents.on("notifications:changed", () => {
|
||||
let notifications =
|
||||
user.get("unread_notifications") + user.get("unread_private_messages");
|
||||
this.notifications =
|
||||
user.unread_notifications + user.unread_private_messages;
|
||||
|
||||
Discourse.updateNotificationCount(notifications);
|
||||
});
|
||||
container
|
||||
.lookup("app-events:main")
|
||||
.on("notifications:changed", this, "_updateTitle");
|
||||
},
|
||||
|
||||
_updateTitle() {
|
||||
Discourse.updateNotificationCount(this.notifications);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -127,10 +127,16 @@ export default Ember.Mixin.create({
|
|||
|
||||
this.appEvents.on(previewClickEvent, this, "_previewClick");
|
||||
|
||||
this.appEvents.on(`topic-header:trigger-${id}`, (username, $target) => {
|
||||
this.appEvents.on(
|
||||
`topic-header:trigger-${id}`,
|
||||
this,
|
||||
"_topicHeaderTrigger"
|
||||
);
|
||||
},
|
||||
|
||||
_topicHeaderTrigger(username, $target) {
|
||||
this.setProperties({ isFixed: true, isDocked: true });
|
||||
return this._show(username, $target);
|
||||
});
|
||||
},
|
||||
|
||||
_bindMobileScroll() {
|
||||
|
@ -281,7 +287,14 @@ export default Ember.Mixin.create({
|
|||
$("#main")
|
||||
.off(clickDataExpand)
|
||||
.off(clickMention);
|
||||
|
||||
this.appEvents.off(previewClickEvent, this, "_previewClick");
|
||||
|
||||
this.appEvents.off(
|
||||
`topic-header:trigger-${this.elementId}`,
|
||||
this,
|
||||
"_topicHeaderTrigger"
|
||||
);
|
||||
},
|
||||
|
||||
keyUp(e) {
|
||||
|
|
|
@ -154,6 +154,18 @@ QUnit.testDone(function() {
|
|||
flushMap();
|
||||
|
||||
server.shutdown();
|
||||
|
||||
// ensures any event not removed is not leaking between tests
|
||||
// most like in intialisers, other places (controller, component...)
|
||||
// should be fixed in code
|
||||
var appEvents = window.Discourse.__container__.lookup("app-events:main");
|
||||
var events = appEvents.__proto__._events;
|
||||
Object.keys(events).forEach(function(eventKey) {
|
||||
var event = events[eventKey];
|
||||
event.forEach(function(listener) {
|
||||
appEvents.off(eventKey, listener.target, listener.fn);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Load ES6 tests
|
||||
|
|
Loading…
Reference in New Issue
Block a user