draft
This commit is contained in:
parent
65671ab7ba
commit
9c3ac133e3
23 changed files with 330 additions and 273 deletions
|
@ -1,32 +0,0 @@
|
|||
class LiveTimer extends HTMLElement {
|
||||
|
||||
render() {
|
||||
this.innerHTML = `
|
||||
<time-formatted hour="numeric" minute="numeric" second="numeric">
|
||||
</time-formatted>
|
||||
`;
|
||||
|
||||
this.timerElem = this.firstElementChild;
|
||||
}
|
||||
|
||||
connectedCallback() { // (2)
|
||||
if (!this.rendered) {
|
||||
this.render();
|
||||
this.rendered = true;
|
||||
}
|
||||
this.timer = setInterval(() => this.update(), 1000);
|
||||
}
|
||||
|
||||
update() {
|
||||
this.date = new Date();
|
||||
this.timerElem.setAttribute('datetime', this.date);
|
||||
this.dispatchEvent(new CustomEvent('tick', { detail: this.date }));
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
clearInterval(this.timer); // important to let the element be garbage-collected
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
customElements.define("live-timer", LiveTimer);
|
Loading…
Add table
Add a link
Reference in a new issue