1 |
|
2 | export default {
|
3 |
|
4 | async setup () {
|
5 |
|
6 | if (window.Reflect === undefined) {
|
7 | window.Reflect = window.Reflect || {};
|
8 | window.Reflect.construct = function (parent, args, child) {
|
9 | const target = child === undefined ? parent : child;
|
10 | const prototype = target.prototype || Object.prototype;
|
11 | const copy = Object.create(prototype);
|
12 | return Function.prototype.apply.call(parent, copy, args) || copy;
|
13 | };
|
14 | }
|
15 |
|
16 | },
|
17 |
|
18 | define (name, constructor) {
|
19 | constructor = constructor || function () {};
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const construct = function () {
|
32 | const instance = window.Reflect.construct(HTMLElement, [], this.constructor);
|
33 | constructor.call(instance);
|
34 | return instance;
|
35 | };
|
36 |
|
37 | const prototypes = Object.getOwnPropertyDescriptors(constructor.prototype);
|
38 |
|
39 | construct.prototype = Object.create(HTMLElement.prototype);
|
40 |
|
41 | // Object.assign(construct, properties);
|
42 | // Object.assign(construct.prototype, prototypes);
|
43 | // Object.defineProperties(construct, properties);
|
44 | Object.defineProperties(construct.prototype, prototypes);
|
45 | Object.defineProperty(construct.prototype, 'constructor', { enumerable: false, writable: true, value: construct });
|
46 |
|
47 | window.customElements.define(name, construct);
|
48 | }
|
49 |
|
50 | }
|