refactor timer to lit

This commit is contained in:
“chrisshank” 2024-12-10 15:35:55 -08:00
parent 90813656a9
commit 9606014617
1 changed files with 7 additions and 9 deletions

View File

@ -1,32 +1,30 @@
import { FolkElement } from './common/folk-element';
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
'folk-timer': FolkTimer; 'folk-timer': FolkTimer;
} }
} }
export class FolkTimer extends HTMLElement { export class FolkTimer extends FolkElement {
static tagName = 'folk-timer'; static tagName = 'folk-timer';
static define() {
if (customElements.get(this.tagName)) return;
customElements.define(this.tagName, this);
}
#timeMs = 0; #timeMs = 0;
#timeoutId: NodeJS.Timeout | -1 = -1; #timeoutId = -1;
#intervalMs = 100; #intervalMs = 100;
connectedCallback() { connectedCallback() {
super.connectedCallback();
this.#updateTime(0); this.#updateTime(0);
} }
start() { start() {
this.#timeoutId = setInterval(this.#updateTime, this.#intervalMs); this.#timeoutId = window.setInterval(this.#updateTime, this.#intervalMs);
} }
stop() { stop() {
clearInterval(this.#timeoutId); window.clearInterval(this.#timeoutId);
this.#timeoutId = -1; this.#timeoutId = -1;
} }