@webtides/element-js 1.2.1 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/BaseElement.js +23 -5
- package/src/dom-parts/ChildNodePart.js +3 -0
package/package.json
CHANGED
package/src/BaseElement.js
CHANGED
|
@@ -191,6 +191,18 @@ class BaseElement extends HTMLElement {
|
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
+
// release dom references
|
|
195
|
+
this.$refs = {};
|
|
196
|
+
|
|
197
|
+
// clear state
|
|
198
|
+
this._state = {};
|
|
199
|
+
|
|
200
|
+
// cancel pending updates
|
|
201
|
+
if (this._batchUpdate) {
|
|
202
|
+
cancelAnimationFrame(this._batchUpdate);
|
|
203
|
+
this._requestedUpdates = [];
|
|
204
|
+
}
|
|
205
|
+
|
|
194
206
|
this.triggerHook('disconnected');
|
|
195
207
|
}
|
|
196
208
|
|
|
@@ -297,16 +309,16 @@ class BaseElement extends HTMLElement {
|
|
|
297
309
|
* Will trigger update() when a property was changed
|
|
298
310
|
* @param {string} property
|
|
299
311
|
* @param {any} value
|
|
300
|
-
* @param {boolean}
|
|
312
|
+
* @param {boolean} isAttribute
|
|
301
313
|
*/
|
|
302
|
-
defineProperty(property, value,
|
|
314
|
+
defineProperty(property, value, isAttribute = false) {
|
|
303
315
|
if (this._state.hasOwnProperty(property)) {
|
|
304
316
|
// property has already been defined as an attribute nothing to do here
|
|
305
317
|
return;
|
|
306
318
|
}
|
|
307
319
|
|
|
308
320
|
// if property did not come from an attribute but has the option to reflect // enabled or custom fn
|
|
309
|
-
if (!
|
|
321
|
+
if (!isAttribute && this._options.propertyOptions[property]?.reflect) {
|
|
310
322
|
this.reflectProperty({ property: property, newValue: value });
|
|
311
323
|
}
|
|
312
324
|
|
|
@@ -325,6 +337,10 @@ class BaseElement extends HTMLElement {
|
|
|
325
337
|
this._state[property].subscribe(this);
|
|
326
338
|
}
|
|
327
339
|
|
|
340
|
+
if (Object.getOwnPropertyDescriptor(this, property)) {
|
|
341
|
+
// instance already has a defined property
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
328
344
|
Object.defineProperty(this, property, {
|
|
329
345
|
get: () => {
|
|
330
346
|
return this._state[property];
|
|
@@ -341,7 +357,7 @@ class BaseElement extends HTMLElement {
|
|
|
341
357
|
newValue.subscribe(this);
|
|
342
358
|
}
|
|
343
359
|
|
|
344
|
-
if (
|
|
360
|
+
if (isAttribute || this._options.propertyOptions[property]?.reflect) {
|
|
345
361
|
this.reflectProperty({ property, newValue, newValueString });
|
|
346
362
|
}
|
|
347
363
|
|
|
@@ -587,8 +603,10 @@ class BaseElement extends HTMLElement {
|
|
|
587
603
|
*/
|
|
588
604
|
removeEvents() {
|
|
589
605
|
this._registeredEvents.forEach(({ eventTarget, eventName, callback }) => {
|
|
590
|
-
|
|
606
|
+
try {
|
|
591
607
|
eventTarget.removeEventListener(eventName, callback);
|
|
608
|
+
} catch (e) {
|
|
609
|
+
console.error('Unable to remove event listener', e);
|
|
592
610
|
}
|
|
593
611
|
});
|
|
594
612
|
this._registeredEvents = [];
|
|
@@ -21,6 +21,9 @@ export const insertNodesBetweenComments = (commentNode, nodes) => {
|
|
|
21
21
|
export const replaceNodesBetweenComments = (commentNode, nodes) => {
|
|
22
22
|
removeNodesBetweenComments(commentNode);
|
|
23
23
|
for (const node of nodes) {
|
|
24
|
+
if (!commentNode.parentNode) {
|
|
25
|
+
console.error(`--- no parent comment ---`);
|
|
26
|
+
}
|
|
24
27
|
commentNode.parentNode.insertBefore(node, commentNode);
|
|
25
28
|
}
|
|
26
29
|
};
|