Skip to content

Commit

Permalink
refactor timer to lit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Dec 10, 2024
1 parent 9081365 commit 9606014
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/folk-timer.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down

0 comments on commit 9606014

Please sign in to comment.