Improved the code style
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 Jan 2021 16:11:56 +0000 (17:11 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 Jan 2021 16:11:56 +0000 (17:11 +0100)
The `break` in `Popover.ts` uses braces for all cases for consistency with the `State.None` case that introduces local variables.

wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js
wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Popover.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ajax/Data.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Bbcode/Collapsible.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Popover.ts

index 0e35100716748966dd2ef2858c707a4a6644af6f..99e97bf20805f13db3166f7a8797eec5d339a993 100644 (file)
@@ -69,11 +69,8 @@ define(["require", "exports"], function (require, exports) {
     function observe() {
         document.querySelectorAll(".jsCollapsibleBbcode").forEach((container) => {
             // find the matching toggle button
-            const toggleButtons = [];
-            container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)").forEach((button) => {
-                if (button.closest(".jsCollapsibleBbcode") === container) {
-                    toggleButtons.push(button);
-                }
+            const toggleButtons = Array.from(container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)")).filter((button) => {
+                return button.closest(".jsCollapsibleBbcode") === container;
             });
             const overflowContainer = container.querySelector(".collapsibleBbcodeOverflow") || container;
             if (toggleButtons.length > 0) {
index 2ef5288302bcf5b246b267a0d48649718d8238d7..73fecc8a14ee1f04c9566d08c5d931aa187a3b22 100644 (file)
@@ -39,9 +39,9 @@ define(["require", "exports", "tslib", "../Ajax", "../Dom/Change/Listener", "../
             this.popover.appendChild(pointer);
             document.body.appendChild(this.popover);
             // event listener
-            this.popover.addEventListener("mouseenter", this.popoverMouseEnter.bind(this));
+            this.popover.addEventListener("mouseenter", () => this.popoverMouseEnter());
             this.popover.addEventListener("mouseleave", () => this.mouseLeave());
-            this.popover.addEventListener("animationend", this.clearContent.bind(this));
+            this.popover.addEventListener("animationend", () => this.clearContent());
             window.addEventListener("beforeunload", () => {
                 this.suspended = true;
                 if (this.timerEnter) {
@@ -242,27 +242,35 @@ define(["require", "exports", "tslib", "../Ajax", "../Dom/Change/Listener", "../
             }
             const cacheId = elementData.element.dataset.cacheId;
             const data = this.cache.get(cacheId);
-            if (data.state === 2 /* Ready */) {
-                this.popoverContent.appendChild(data.content);
-                this.rebuild();
-            }
-            else if (data.state === 0 /* None */) {
-                data.state = 1 /* Loading */;
-                const handler = this.handlers.get(elementData.identifier);
-                if (handler.loadCallback) {
-                    handler.loadCallback(elementData.objectId, this, elementData.element);
+            switch (data.state) {
+                case 2 /* Ready */: {
+                    this.popoverContent.appendChild(data.content);
+                    this.rebuild();
+                    break;
+                }
+                case 0 /* None */: {
+                    data.state = 1 /* Loading */;
+                    const handler = this.handlers.get(elementData.identifier);
+                    if (handler.loadCallback) {
+                        handler.loadCallback(elementData.objectId, this, elementData.element);
+                    }
+                    else if (handler.dboAction) {
+                        const callback = (data) => {
+                            this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
+                            return true;
+                        };
+                        this.ajaxApi({
+                            actionName: "getPopover",
+                            className: handler.dboAction,
+                            interfaceName: "wcf\\data\\IPopoverAction",
+                            objectIDs: [elementData.objectId],
+                        }, callback, callback);
+                    }
+                    break;
                 }
-                else if (handler.dboAction) {
-                    const callback = (data) => {
-                        this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
-                        return true;
-                    };
-                    this.ajaxApi({
-                        actionName: "getPopover",
-                        className: handler.dboAction,
-                        interfaceName: "wcf\\data\\IPopoverAction",
-                        objectIDs: [elementData.objectId],
-                    }, callback, callback);
+                case 1 /* Loading */: {
+                    // Do not interrupt inflight requests.
+                    break;
                 }
             }
         }
index c5fa0b6f1d56fe5d88bef804bd4312be680bdf5b..c46fa2a4d3d2aab2bfc16a55255b1a6e62f9d96b 100644 (file)
@@ -28,7 +28,7 @@ export interface DatabaseObjectActionResponse extends ResponseData {
     | any[];
 }
 
-// Return `false` to suppress the error message.
+/** Return `false` to suppress the error message. */
 export type CallbackFailure = (
   data: ResponseData,
   responseText: string,
index cf0c0e5fc3d97e0d0e0c18de62bce50419c8368f..f1323f4643106494bfb8aac7b062c89902f19307 100644 (file)
@@ -68,11 +68,10 @@ function toggleContainer(container: HTMLElement, toggleButtons: HTMLElement[], e
 export function observe(): void {
   document.querySelectorAll(".jsCollapsibleBbcode").forEach((container: HTMLElement) => {
     // find the matching toggle button
-    const toggleButtons: HTMLElement[] = [];
-    container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)").forEach((button: HTMLElement) => {
-      if (button.closest(".jsCollapsibleBbcode") === container) {
-        toggleButtons.push(button);
-      }
+    const toggleButtons = Array.from<HTMLElement>(
+      container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)"),
+    ).filter((button) => {
+      return button.closest(".jsCollapsibleBbcode") === container;
     });
 
     const overflowContainer = (container.querySelector(".collapsibleBbcodeOverflow") as HTMLElement) || container;
index a311ac378e3c12f48329a9522f324b5bdb9f30b6..6bd30fd3075faf0996761e975ddcda036632f906 100644 (file)
@@ -86,10 +86,10 @@ class ControllerPopover implements AjaxCallbackObject {
     document.body.appendChild(this.popover);
 
     // event listener
-    this.popover.addEventListener("mouseenter", this.popoverMouseEnter.bind(this));
+    this.popover.addEventListener("mouseenter", () => this.popoverMouseEnter());
     this.popover.addEventListener("mouseleave", () => this.mouseLeave());
 
-    this.popover.addEventListener("animationend", this.clearContent.bind(this));
+    this.popover.addEventListener("animationend", () => this.clearContent());
 
     window.addEventListener("beforeunload", () => {
       this.suspended = true;
@@ -334,33 +334,46 @@ class ControllerPopover implements AjaxCallbackObject {
     const cacheId = elementData.element.dataset.cacheId!;
     const data = this.cache.get(cacheId)!;
 
-    if (data.state === State.Ready) {
-      this.popoverContent.appendChild(data.content!);
-
-      this.rebuild();
-    } else if (data.state === State.None) {
-      data.state = State.Loading;
-
-      const handler = this.handlers.get(elementData.identifier)!;
-      if (handler.loadCallback) {
-        handler.loadCallback(elementData.objectId, this, elementData.element);
-      } else if (handler.dboAction) {
-        const callback = (data) => {
-          this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
-
-          return true;
-        };
-
-        this.ajaxApi(
-          {
-            actionName: "getPopover",
-            className: handler.dboAction,
-            interfaceName: "wcf\\data\\IPopoverAction",
-            objectIDs: [elementData.objectId],
-          },
-          callback,
-          callback,
-        );
+    switch (data.state) {
+      case State.Ready: {
+        this.popoverContent.appendChild(data.content!);
+
+        this.rebuild();
+
+        break;
+      }
+
+      case State.None: {
+        data.state = State.Loading;
+
+        const handler = this.handlers.get(elementData.identifier)!;
+        if (handler.loadCallback) {
+          handler.loadCallback(elementData.objectId, this, elementData.element);
+        } else if (handler.dboAction) {
+          const callback = (data) => {
+            this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
+
+            return true;
+          };
+
+          this.ajaxApi(
+            {
+              actionName: "getPopover",
+              className: handler.dboAction,
+              interfaceName: "wcf\\data\\IPopoverAction",
+              objectIDs: [elementData.objectId],
+            },
+            callback,
+            callback,
+          );
+        }
+
+        break;
+      }
+
+      case State.Loading: {
+        // Do not interrupt inflight requests.
+        break;
       }
     }
   }