closed shadowRoot and changed pages, components, layout to extend base class

This commit is contained in:
Fran Jurmanović
2021-06-02 13:19:32 +02:00
parent f01c328716
commit 91032927fd
25 changed files with 206 additions and 109 deletions

View File

@@ -0,0 +1,37 @@
import { html, render } from "@github/jtml";
import { AppMainElement } from "components/";
import { closest } from "core/utils";
class BasePageElement extends HTMLElement {
@closest appMain: AppMainElement;
bindEvents = () => {
const _elems = this.querySelectorAll("[data-action]");
_elems?.forEach((el) => {
for (const action of (el.getAttribute("data-action") || "")
.trim()
.split(/\s+/)) {
const eventSep = action.lastIndexOf(":");
const methodSep = action.lastIndexOf("#");
const tag = action.slice(eventSep + 1, methodSep);
const type = action.slice(0, eventSep);
const method = action.slice(methodSep + 1);
if (tag.toUpperCase() === this.tagName) {
this.addEventListener(type, this[method]);
}
}
});
};
render = () => {
return html``;
};
update = () => {
render(this.render(), this);
this.bindEvents();
};
}
export default BasePageElement;