wcb/WebComponent.mjs
2023-09-17 00:48:01 +02:00

29 lines
543 B
JavaScript

// @ts-check
export class WebComponent extends HTMLElement {
get template() {
return "";
}
/**
* triggered when an attribute value changed
*/
onChanges({ previousValue, currentValue }) {}
connectedCallback() {
this.render();
}
attributeChangedCallback(property, previousValue, currentValue) {
if (previousValue !== currentValue) {
this[property] = currentValue;
this.render();
}
this.onChanges({previousValue, currentValue});
}
render() {
this.innerHTML = this.template;
}
}