import {LiveComponent} from "../../server/component/component";
export class CounterComponent extends LiveComponent {
tickTimer: any;
mount(): void {
console.log('mount', this.socket.isConnected());
this.socket.assign({
count: 0,
isConnected: this.socket.isConnected()
});
this.tickTimer = setInterval(() => {
this.socket.assign({
count: this.socket.getState().count + 1,
isConnected: this.socket.isConnected()
});
}, 1000);
}
unmount(): void {
console.log('umount', this.socket.isConnected());
clearInterval(this.tickTimer);
}
render(): string {
return this.renderEJS("<h1>Counter <%=count%></h1> <p>isConnected: <%=isConnected%></p>");
}
}