Support for legacy class inheritance (ES5-style)
authorAlexander Ebert <ebert@woltlab.com>
Sat, 31 Oct 2020 17:26:44 +0000 (18:26 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 31 Oct 2020 17:26:44 +0000 (18:26 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Core.js
wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts

index bd232bd328746ad40f3ef30a66c7cf10f3c85d85..e0fedbedbc1b896ac37a76167e7b8fa49e3e3592 100644 (file)
@@ -10,7 +10,7 @@
 define(["require", "exports"], function (require, exports) {
     "use strict";
     Object.defineProperty(exports, "__esModule", { value: true });
-    exports.debounce = exports.stringToBool = exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0;
+    exports.enableLegacyInheritance = exports.debounce = exports.stringToBool = exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0;
     const _clone = function (variable) {
         if (typeof variable === "object" && (Array.isArray(variable) || isPlainObject(variable))) {
             return _cloneObject(variable);
@@ -230,4 +230,13 @@ define(["require", "exports"], function (require, exports) {
         };
     }
     exports.debounce = debounce;
+    function enableLegacyInheritance(legacyClass) {
+        legacyClass.call = function (thisValue, ...args) {
+            const constructed = Reflect.construct(legacyClass, args, thisValue.constructor);
+            Object.entries(constructed).forEach(([key, value]) => {
+                thisValue[key] = value;
+            });
+        };
+    }
+    exports.enableLegacyInheritance = enableLegacyInheritance;
 });
index c83178089caf8ae2b9a408f5d8b693a94fc43ef5..708cb30a041446d6c71a7ea1c13c8dd706453071 100644 (file)
@@ -329,5 +329,6 @@ define(["require", "exports", "tslib", "./Ajax/Request", "./Core", "./Dom/Change
             return this._upload(null, file);
         }
     }
+    Core.enableLegacyInheritance(Upload);
     return Upload;
 });
index f7d78d149b6afaec82f89bd3ba776c688451db72..60cfa07914f357f2cccee3df8e70784a2dde58b7 100644 (file)
@@ -260,3 +260,12 @@ export function debounce<F extends DebounceCallback>(
     }
   };
 }
+
+export function enableLegacyInheritance<T>(legacyClass: T): void {
+  (legacyClass as any).call = function (thisValue, ...args) {
+    const constructed = Reflect.construct(legacyClass as any, args, thisValue.constructor);
+    Object.entries(constructed).forEach(([key, value]) => {
+      thisValue[key] = value;
+    });
+  };
+}
index c61df61b0e02fc17de0a603b0bf1268fbe643cdc..84e39fac4e500daa5e88e174073c880e38ca388a 100644 (file)
@@ -429,4 +429,6 @@ abstract class Upload {
   }
 }
 
+Core.enableLegacyInheritance(Upload);
+
 export = Upload;