| 41 | }) |
| 42 | @observer |
| 43 | export class ClassClock extends HTMLElement implements WebCell { |
| 44 | @attribute |
| 45 | @observable |
| 46 | accessor time = new Date(); |
| 47 | |
| 48 | private timer: number; |
| 49 | |
| 50 | connectedCallback() { |
| 51 | this.timer = window.setInterval(() => (this.time = new Date()), Second); |
| 52 | } |
| 53 | |
| 54 | disconnectedCallback() { |
| 55 | clearInterval(this.timer); |
| 56 | } |
| 57 | |
| 58 | @reaction(({ time }) => time) |
| 59 | handleReaction(newValue: Date, oldValue: Date, reaction: IReactionPublic) { |
| 60 | console.info(newValue, oldValue, reaction); |
| 61 | } |
| 62 | |
| 63 | @on('click', 'time') |
| 64 | handleClick(event: MouseEvent, currentTarget: HTMLTimeElement) { |
| 65 | console.info(event, currentTarget); |
| 66 | } |
| 67 | |
| 68 | render() { |
| 69 | const { time } = this; |
| 70 | |
| 71 | return ( |
| 72 | <time dateTime={time.toJSON()}> |
| 73 | Class Clock: {time.toLocaleString()} |
| 74 | </time> |
| 75 | ); |
| 76 | } |
| 77 | } |