feat: some refactoring and cleanup

This commit is contained in:
Daniel Ledda
2022-05-25 23:49:20 +02:00
parent b3ee2af7c5
commit 7aa8941227
11 changed files with 184 additions and 137 deletions

34
lib/Rung.ts Normal file
View File

@@ -0,0 +1,34 @@
export type RungOptions = {};
export default abstract class Rung {
protected el: HTMLElement | null = null;
protected constructor(options: RungOptions) {}
render(): HTMLElement {
if (!this.el) {
this.el = this.build();
}
return this.el;
}
protected getEl(): HTMLElement {
return this.render();
}
redraw(): void {
const oldNode = this.el;
if (!oldNode || !this.el) {
return;
}
const parent = this.el.parentElement;
if (parent) {
this.el = this.build();
parent.replaceChild(this.el, oldNode);
} else {
this.render();
}
}
protected abstract build(): HTMLElement;
}