Skip to content

Instantly share code, notes, and snippets.

@leetheguy
Last active May 31, 2019 20:16
Show Gist options
  • Save leetheguy/13fa750b18ade50aff3ec487ca3cfd69 to your computer and use it in GitHub Desktop.
Save leetheguy/13fa750b18ade50aff3ec487ca3cfd69 to your computer and use it in GitHub Desktop.
import { Component, State } from '@stencil/core';
@Component({
tag: 'analog-clock',
})
export class AnalogClock {
timer: number;
@State() time: number = Date.now();
componentDidLoad() {
this.timer = window.setInterval(() => {
this.time = Date.now();
}, 250);
}
componentDidUnload() {
clearInterval(this.timer);
}
get hour(): number {
return new Date(this.time).getHours();
}
get minute(): number {
return new Date(this.time).getMinutes();
}
get second(): number {
return new Date(this.time).getSeconds();
}
render() {
return (
</div>
<clock-face hour={this.hour} minute={this.minute} second={this.second}/>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment