mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 16:29:32 +08:00
FIX: In test mode, initializers were modifying classes over and over
This adds a new property, `pluginId` which you can pass to `modifyClass` which prevent the class from being modified over and over again. This also includes a fix for polls which was leaking state between tests which this new functionality exposed.
This commit is contained in:
@ -4,6 +4,7 @@ import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
function initializePollUIBuilder(api) {
|
||||
api.modifyClass("controller:composer", {
|
||||
pluginId: "discourse-poll-ui-builder",
|
||||
@discourseComputed(
|
||||
"siteSettings.poll_enabled",
|
||||
"siteSettings.poll_minimum_trust_level_to_create",
|
||||
|
@ -4,10 +4,30 @@ import { getRegister } from "discourse-common/lib/get-owner";
|
||||
import { observes } from "discourse-common/utils/decorators";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
const PLUGIN_ID = "discourse-poll";
|
||||
let _glued = [];
|
||||
let _interval = null;
|
||||
|
||||
function rerender() {
|
||||
_glued.forEach((g) => g.queueRerender());
|
||||
}
|
||||
|
||||
function cleanUpPolls() {
|
||||
if (_interval) {
|
||||
clearInterval(_interval);
|
||||
_interval = null;
|
||||
}
|
||||
|
||||
_glued.forEach((g) => g.cleanUp());
|
||||
_glued = [];
|
||||
}
|
||||
|
||||
function initializePolls(api) {
|
||||
const register = getRegister(api);
|
||||
cleanUpPolls();
|
||||
|
||||
api.modifyClass("controller:topic", {
|
||||
pluginId: PLUGIN_ID,
|
||||
subscribe() {
|
||||
this._super(...arguments);
|
||||
this.messageBus.subscribe("/polls/" + this.get("model.id"), (msg) => {
|
||||
@ -23,14 +43,8 @@ function initializePolls(api) {
|
||||
},
|
||||
});
|
||||
|
||||
let _glued = [];
|
||||
let _interval = null;
|
||||
|
||||
function rerender() {
|
||||
_glued.forEach((g) => g.queueRerender());
|
||||
}
|
||||
|
||||
api.modifyClass("model:post", {
|
||||
pluginId: PLUGIN_ID,
|
||||
_polls: null,
|
||||
pollsObject: null,
|
||||
|
||||
@ -110,16 +124,6 @@ function initializePolls(api) {
|
||||
});
|
||||
}
|
||||
|
||||
function cleanUpPolls() {
|
||||
if (_interval) {
|
||||
clearInterval(_interval);
|
||||
_interval = null;
|
||||
}
|
||||
|
||||
_glued.forEach((g) => g.cleanUp());
|
||||
_glued = [];
|
||||
}
|
||||
|
||||
api.includePostAttributes("polls", "polls_votes");
|
||||
api.decorateCooked(attachPolls, { onlyStream: true, id: "discourse-poll" });
|
||||
api.cleanupStream(cleanUpPolls);
|
||||
|
Reference in New Issue
Block a user