Moved variables into the module scope
authorAlexander Ebert <ebert@woltlab.com>
Tue, 3 Nov 2020 11:32:41 +0000 (12:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 3 Nov 2020 11:32:41 +0000 (12:32 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Like/Handler.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Like/Handler.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Reaction/Handler.ts

index 551da42664ca6b1cb9321f77b554179de4d80c3c..82b67793203652ae56ab83624e1c19e9a88b3b35 100644 (file)
@@ -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) {
index 9bd0fd6c4b9094bda805be09fccb240d29dbc47e..8b0bcbc827213fc9a832607ae0cf847c94ad1a88 100644 (file)
@@ -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);
index f488da7ef24dfd1fed3a7596313a7dac481a2ecb..9de4a2373bc44bb49b8d7382937b4bc3e5aa150e 100644 (file)
@@ -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.
index f53ea405e69b3f67202a4ed69c1e74285616c897..db4d8451785158ec0201aaa7f25eb9d3e7a37662 100644 (file)
@@ -55,8 +55,10 @@ interface ElementData {
   users: LikeUsers;
 }
 
+const availableReactions = new Map(Object.entries(window.REACTION_TYPES));
+
 class UiLikeHandler {
-  protected readonly _containers = new Map<HTMLElement, ElementData>();
+  protected readonly _containers = new WeakMap<HTMLElement, ElementData>();
   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) {
index f02a96bc599684f38116eb10ec77ecfc4c84df79..77d7b8b7c42a56c414edb13599d6b9bea970a97e 100644 (file)
@@ -47,6 +47,8 @@ interface AjaxResponse extends ResponseData {
   };
 }
 
+const availableReactions = new Map<string, Reaction>(Object.entries(window.REACTION_TYPES));
+
 class CountButtons {
   protected readonly _containers = new Map<string, ElementData>();
   protected _currentObjectId = 0;
@@ -154,8 +156,6 @@ class CountButtons {
         }
       });
 
-      const availableReactions = new Map<string, Reaction>(Object.entries(window.REACTION_TYPES));
-
       existingReactions.forEach((count, reactionTypeId) => {
         if (sortedElements.has(reactionTypeId)) {
           const reaction = sortedElements.get(reactionTypeId)!;
index c5d0108b6453e733934abbad2001eb28a36d2c7f..dff07fe58ea4c139d8f63df61d09bcce5b18e5b7 100644 (file)
@@ -51,6 +51,8 @@ interface AjaxResponse {
   };
 }
 
+const availableReactions = Object.values(window.REACTION_TYPES);
+
 class UiReactionHandler {
   readonly countButtons: CountButtons;
   protected readonly _cache = new Map<string, unknown>();
@@ -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);
   }
 
   /**