Skip to content

Commit a543b83

Browse files
committed
posibility to change dce
1 parent 7c09dbb commit a543b83

2 files changed

Lines changed: 42 additions & 33 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"description": "Base Custom Webcomponent",
33
"name": "@node-projects/base-custom-webcomponent",
4-
"version": "0.25.2",
4+
"version": "0.25.3",
55
"type": "module",
66
"main": "./dist/index.js",
77
"author": "",

src/DeclaritiveBaseCustomWebcomponent.ts

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,51 @@ class DeclaritiveBaseCustomWebcomponent extends BaseCustomWebComponentNoAttached
5050
}
5151
const name = this.name;
5252
const definingElement = this;
53-
window[name] = function () {
54-
if (window[name].template === undefined)
55-
window[name].template = definingElement.querySelector('template');
56-
const instance = Reflect.construct(BaseDeclaritiveWebcomponent, [], window[name]);
5753

58-
for (let p in props) {
59-
Object.defineProperty(instance, p, {
60-
get() {
61-
return this['_' + p];
62-
},
63-
set(newValue) {
64-
if (this['_' + p] !== newValue) {
65-
this['_' + p] = newValue;
66-
//@ts-ignore
67-
if (this.constructor._enableBindings)
68-
this._bindingsRefresh(p);
69-
instance.dispatchEvent(new CustomEvent(camelToDashCase(p) + '-changed', { detail: { newValue } }));
70-
}
71-
},
72-
enumerable: true,
73-
configurable: true,
74-
});
75-
if (props[p].default) {
76-
instance['_' + p] = props[p].default;
54+
if (window[name]) {
55+
window[name].template = undefined;
56+
//window[name].style = style;
57+
window[name].properties = props;
58+
window[name]._propertiesDictionary = null;
59+
window[name]._enableBindings = this.enableBindings;
60+
} else {
61+
window[name] = function () {
62+
if (window[name].template === undefined)
63+
window[name].template = definingElement.querySelector('template');
64+
const instance = Reflect.construct(BaseDeclaritiveWebcomponent, [], window[name]);
65+
66+
for (let p in props) {
67+
Object.defineProperty(instance, p, {
68+
get() {
69+
return this['_' + p];
70+
},
71+
set(newValue) {
72+
if (this['_' + p] !== newValue) {
73+
this['_' + p] = newValue;
74+
//@ts-ignore
75+
if (this.constructor._enableBindings)
76+
this._bindingsRefresh(p);
77+
instance.dispatchEvent(new CustomEvent(camelToDashCase(p) + '-changed', { detail: { newValue } }));
78+
}
79+
},
80+
enumerable: true,
81+
configurable: true,
82+
});
83+
if (props[p].default) {
84+
instance['_' + p] = props[p].default;
85+
}
7786
}
87+
return instance;
7888
}
79-
return instance;
80-
}
8189

82-
//window[name].style = style;
83-
window[name].properties = props;
84-
window[name]._propertiesDictionary = null;
85-
window[name]._enableBindings = this.enableBindings;
86-
window[name].prototype = Object.create(BaseDeclaritiveWebcomponent.prototype, { constructor: { value: window[name] } })
87-
if (!customElements.get(name))
88-
customElements.define(name, window[name]);
90+
//window[name].style = style;
91+
window[name].properties = props;
92+
window[name]._propertiesDictionary = null;
93+
window[name]._enableBindings = this.enableBindings;
94+
window[name].prototype = Object.create(BaseDeclaritiveWebcomponent.prototype, { constructor: { value: window[name] } })
95+
if (!customElements.get(name))
96+
customElements.define(name, window[name]);
97+
}
8998
}
9099
}
91100

0 commit comments

Comments
 (0)