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 {
interface HTMLElementTagNameMap {
'folk-timer': FolkTimer;
}
}
export class FolkTimer extends HTMLElement {
export class FolkTimer extends FolkElement {
static tagName = 'folk-timer';
static define() {
if (customElements.get(this.tagName)) return;
customElements.define(this.tagName, this);
}
#timeMs = 0;
#timeoutId: NodeJS.Timeout | -1 = -1;
#timeoutId = -1;
#intervalMs = 100;
connectedCallback() {
super.connectedCallback();
this.#updateTime(0);
}
start() {
this.#timeoutId = setInterval(this.#updateTime, this.#intervalMs);
this.#timeoutId = window.setInterval(this.#updateTime, this.#intervalMs);
}
stop() {
clearInterval(this.#timeoutId);
window.clearInterval(this.#timeoutId);
this.#timeoutId = -1;
}