Convert `Dom/Change/Listener` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Fri, 16 Oct 2020 14:08:30 +0000 (16:08 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Oct 2020 11:26:55 +0000 (12:26 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Change/Listener.js
wcfsetup/install/files/ts/WoltLabSuite/Core/CallbackList.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Change/Listener.ts [new file with mode: 0644]

index ef87db6ae629c54797de144eafdce1917fbdcfd6..15771affc88d3e87d75c50f61da349424a25385a 100644 (file)
@@ -1,51 +1,46 @@
 /**
  * Allows to be informed when the DOM may have changed and
  * new elements that are relevant to you may have been added.
- * 
- * @author     Tim Duesterhus
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     Dom/ChangeListener (alias)
- * @module     WoltLabSuite/Core/Dom/Change/Listener
+ *
+ * @author  Tim Duesterhus
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  Dom/ChangeListener (alias)
+ * @module  WoltLabSuite/Core/Dom/Change/Listener
  */
-define(['CallbackList'], function(CallbackList) {
-       "use strict";
-       
-       var _callbackList = new CallbackList();
-       var _hot = false;
-       
-       /**
-        * @exports     WoltLabSuite/Core/Dom/Change/Listener
-        */
-       return {
-               /**
-                * @see WoltLabSuite/Core/CallbackList#add
-                */
-               add: _callbackList.add.bind(_callbackList),
-               
-               /**
-                * @see WoltLabSuite/Core/CallbackList#remove
-                */
-               remove: _callbackList.remove.bind(_callbackList),
-               
-               /**
-                * Triggers the execution of all the listeners.
-                * Use this function when you added new elements to the DOM that might
-                * be relevant to others.
-                * While this function is in progress further calls to it will be ignored.
-                */
-               trigger: function() {
-                       if (_hot) return;
-                       
-                       try {
-                               _hot = true;
-                               _callbackList.forEach(null, function(callback) {
-                                       callback();
-                               });
-                       }
-                       finally {
-                               _hot = false;
-                       }
-               }
-       };
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+define(["require", "exports", "../../CallbackList"], function (require, exports, CallbackList_1) {
+    "use strict";
+    CallbackList_1 = __importDefault(CallbackList_1);
+    const _callbackList = new CallbackList_1.default();
+    let _hot = false;
+    return {
+        /**
+         * @see CallbackList.add
+         */
+        add: _callbackList.add.bind(_callbackList),
+        /**
+         * @see CallbackList.remove
+         */
+        remove: _callbackList.remove.bind(_callbackList),
+        /**
+         * Triggers the execution of all the listeners.
+         * Use this function when you added new elements to the DOM that might
+         * be relevant to others.
+         * While this function is in progress further calls to it will be ignored.
+         */
+        trigger() {
+            if (_hot)
+                return;
+            try {
+                _hot = true;
+                _callbackList.forEach(null, callback => callback());
+            }
+            finally {
+                _hot = false;
+            }
+        },
+    };
 });
index 94a43a785cf563ec03092547429f5fd15182ab9b..d888ecd374fb7df10b686b9d5376761011e12bc5 100644 (file)
@@ -47,6 +47,6 @@ class CallbackList {
   }
 }
 
-type Callback = () => void;
+type Callback = (...args: any[]) => void;
 
 export = CallbackList;
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Change/Listener.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Change/Listener.ts
new file mode 100644 (file)
index 0000000..230fbb4
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Allows to be informed when the DOM may have changed and
+ * new elements that are relevant to you may have been added.
+ *
+ * @author  Tim Duesterhus
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  Dom/ChangeListener (alias)
+ * @module  WoltLabSuite/Core/Dom/Change/Listener
+ */
+
+import CallbackList from '../../CallbackList';
+
+const _callbackList = new CallbackList();
+let _hot = false;
+
+export = {
+  /**
+   * @see CallbackList.add
+   */
+  add: _callbackList.add.bind(_callbackList),
+
+  /**
+   * @see CallbackList.remove
+   */
+  remove: _callbackList.remove.bind(_callbackList),
+
+  /**
+   * Triggers the execution of all the listeners.
+   * Use this function when you added new elements to the DOM that might
+   * be relevant to others.
+   * While this function is in progress further calls to it will be ignored.
+   */
+  trigger(): void {
+    if (_hot) return;
+
+    try {
+      _hot = true;
+      _callbackList.forEach(null, callback => callback());
+    } finally {
+      _hot = false;
+    }
+  },
+}