mirror of
https://github.com/FJurmanovic/wallet-web.git
synced 2026-11-11 07:41:09 +00:00
fixed types
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { html, render } from "@github/jtml";
|
||||
import { html, render, TemplateResult } from "@github/jtml";
|
||||
import { AppMainElement } from "components/";
|
||||
import { closest } from "core/utils";
|
||||
|
||||
class BaseElement extends HTMLElement {
|
||||
@closest appMain: AppMainElement;
|
||||
private _appMain: AppMainElement;
|
||||
private elementDisconnectCallbacks: Array<Function> = [];
|
||||
constructor() {
|
||||
super();
|
||||
this.connectedCallback = this.connectedCallback.bind(this);
|
||||
this.disconnectedCallback = this.disconnectedCallback.bind(this);
|
||||
}
|
||||
|
||||
bindEvents = () => {
|
||||
bindEvents = (): void => {
|
||||
const _elems = this.querySelectorAll("[data-action]");
|
||||
_elems?.forEach((el) => {
|
||||
for (const action of (el.getAttribute("data-action") || "")
|
||||
@@ -41,35 +44,37 @@ class BaseElement extends HTMLElement {
|
||||
});
|
||||
};
|
||||
|
||||
render = () => {
|
||||
render = (): TemplateResult => {
|
||||
return html``;
|
||||
};
|
||||
|
||||
update = () => {
|
||||
update = (): void => {
|
||||
render(this.render(), this);
|
||||
this.bindEvents();
|
||||
};
|
||||
|
||||
connectedCallback() {
|
||||
connectedCallback(): void {
|
||||
this.elementConnected();
|
||||
this._appMain = this.appMain;
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
this.elementDisconnected();
|
||||
disconnectedCallback(): void {
|
||||
const { _appMain } = this;
|
||||
this.elementDisconnected(_appMain);
|
||||
if (Array.isArray(this.elementDisconnectCallbacks)) {
|
||||
this.elementDisconnectCallbacks.forEach((callback: Function) => {
|
||||
if (typeof callback == "function") {
|
||||
callback();
|
||||
callback(_appMain);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
elementConnected = () => {
|
||||
elementConnected = (): void => {
|
||||
this.update();
|
||||
};
|
||||
|
||||
elementDisconnected = () => {};
|
||||
elementDisconnected = (appMain: AppMainElement): void => {};
|
||||
}
|
||||
|
||||
export default BaseElement;
|
||||
|
||||
@@ -9,7 +9,7 @@ class BaseLayoutElement extends BaseElement {
|
||||
super();
|
||||
}
|
||||
|
||||
get slotTag() {
|
||||
get slotTag(): string {
|
||||
return this.appSlot?.firstElementChild?.tagName;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class BaseLayoutElement extends BaseElement {
|
||||
return tag?.tagName === this.slotTag;
|
||||
};
|
||||
|
||||
setElement = (newTag: string) => {
|
||||
setElement = (newTag: string): void => {
|
||||
const _appSlot = `<div data-target="base-layout.content"><${newTag}></${newTag}></div>`;
|
||||
this._appSlot = _appSlot;
|
||||
this.appSlot.innerHTML = _appSlot;
|
||||
|
||||
Reference in New Issue
Block a user