Last active
May 31, 2019 20:16
-
-
Save leetheguy/13fa750b18ade50aff3ec487ca3cfd69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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