summaryrefslogtreecommitdiff
path: root/app/javascript/controllers/clock_controller.js
blob: 53a10149e0acb354b858bcae46467e93e054d893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Controller } from "stimulus";

export default class extends Controller {
  static targets = [ "clock" ];

  static values = {
    time: String,
  }

  connect() {
    this.load();
    let controller = this;
    this.clockInterval = setInterval(function() {
      controller.load();
    }, 20 * 1000);
  }

  disconnect() {
    clearInterval(this.clockInterval);
  }

  load() {
    fetch(`/clock`)
      .then(response => response.text())
      .then(html => {
        this.clockTarget.innerHTML = html;
      });
  }
}