From: Alexander Ebert Date: Tue, 3 Nov 2020 11:32:41 +0000 (+0100) Subject: Moved variables into the module scope X-Git-Tag: 5.4.0_Alpha_1~647^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b0850797fe00efc82ee3a1ab766daad90e80cb70;p=GitHub%2FWoltLab%2FWCF.git Moved variables into the module scope --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Like/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Like/Handler.js index 551da42664..82b6779320 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Like/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Like/Handler.js @@ -15,12 +15,13 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Change/Listener" StringUtil = tslib_1.__importStar(StringUtil); Handler_1 = tslib_1.__importDefault(Handler_1); User_1 = tslib_1.__importDefault(User_1); + const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); class UiLikeHandler { /** * Initializes the like handler. */ constructor(objectType, opts) { - this._containers = new Map(); + this._containers = new WeakMap(); if (!opts.containerSelector) { throw new Error("[WoltLabSuite/Core/Ui/Like/Handler] Expected a non-empty string for option 'containerSelector'."); } @@ -109,7 +110,6 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Change/Listener" else { summaryList.classList.add("reactionSummaryListTiny"); } - const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); Object.entries(elementData.users).forEach(([reactionTypeId, count]) => { const reaction = availableReactions.get(reactionTypeId); if (reactionTypeId === "reactionTypeID" || !reaction) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js index 9bd0fd6c4b..8b0bcbc827 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js @@ -16,6 +16,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch EventHandler = tslib_1.__importStar(EventHandler); StringUtil = tslib_1.__importStar(StringUtil); Dialog_1 = tslib_1.__importDefault(Dialog_1); + const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); class CountButtons { /** * Initializes the like handler. @@ -98,7 +99,6 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch reaction.remove(); } }); - const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); existingReactions.forEach((count, reactionTypeId) => { if (sortedElements.has(reactionTypeId)) { const reaction = sortedElements.get(reactionTypeId); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js index f488da7ef2..9de4a2373b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js @@ -17,6 +17,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch CloseOverlay_1 = tslib_1.__importDefault(CloseOverlay_1); UiScreen = tslib_1.__importStar(UiScreen); CountButtons_1 = tslib_1.__importDefault(CountButtons_1); + const availableReactions = Object.values(window.REACTION_TYPES); class UiReactionHandler { /** * Initializes the reaction handler. @@ -89,7 +90,6 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch // The element may have no react button. return; } - const availableReactions = Object.values(window.REACTION_TYPES); if (availableReactions.length === 1) { const reaction = availableReactions[0]; elementData.reactButton.title = reaction.title; @@ -172,7 +172,6 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch event.preventDefault(); event.stopPropagation(); } - const availableReactions = Object.values(window.REACTION_TYPES); if (availableReactions.length === 1) { const reaction = availableReactions[0]; this._popoverCurrentObjectId = objectId; @@ -282,7 +281,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch * Sort the reaction types by the showOrder field. */ _getSortedReactionTypes() { - return Object.values(window.REACTION_TYPES).sort((a, b) => a.showOrder - b.showOrder); + return availableReactions.sort((a, b) => a.showOrder - b.showOrder); } /** * Closes the react popover. diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Like/Handler.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Like/Handler.ts index f53ea405e6..db4d845178 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Like/Handler.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Like/Handler.ts @@ -55,8 +55,10 @@ interface ElementData { users: LikeUsers; } +const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); + class UiLikeHandler { - protected readonly _containers = new Map(); + protected readonly _containers = new WeakMap(); protected readonly _objectType: string; protected readonly _options: LikeHandlerOptions; @@ -173,7 +175,6 @@ class UiLikeHandler { summaryList.classList.add("reactionSummaryListTiny"); } - const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); Object.entries(elementData.users).forEach(([reactionTypeId, count]) => { const reaction = availableReactions.get(reactionTypeId); if (reactionTypeId === "reactionTypeID" || !reaction) { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts index f02a96bc59..77d7b8b7c4 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts @@ -47,6 +47,8 @@ interface AjaxResponse extends ResponseData { }; } +const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); + class CountButtons { protected readonly _containers = new Map(); protected _currentObjectId = 0; @@ -154,8 +156,6 @@ class CountButtons { } }); - const availableReactions = new Map(Object.entries(window.REACTION_TYPES)); - existingReactions.forEach((count, reactionTypeId) => { if (sortedElements.has(reactionTypeId)) { const reaction = sortedElements.get(reactionTypeId)!; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/Handler.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/Handler.ts index c5d0108b64..dff07fe58e 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/Handler.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/Handler.ts @@ -51,6 +51,8 @@ interface AjaxResponse { }; } +const availableReactions = Object.values(window.REACTION_TYPES); + class UiReactionHandler { readonly countButtons: CountButtons; protected readonly _cache = new Map(); @@ -152,7 +154,6 @@ class UiReactionHandler { return; } - const availableReactions = Object.values(window.REACTION_TYPES); if (availableReactions.length === 1) { const reaction = availableReactions[0]; elementData.reactButton.title = reaction.title; @@ -244,7 +245,6 @@ class UiReactionHandler { event.stopPropagation(); } - const availableReactions = Object.values(window.REACTION_TYPES); if (availableReactions.length === 1) { const reaction = availableReactions[0]; this._popoverCurrentObjectId = objectId; @@ -379,7 +379,7 @@ class UiReactionHandler { * Sort the reaction types by the showOrder field. */ protected _getSortedReactionTypes(): Reaction[] { - return Object.values(window.REACTION_TYPES).sort((a, b) => a.showOrder - b.showOrder); + return availableReactions.sort((a, b) => a.showOrder - b.showOrder); } /**