main
 1import ApplicationController from './application_controller';
 2
 3export default class extends ApplicationController {
 4  connect() {
 5    this.load();
 6
 7    if (this.data.has('refreshInterval')) {
 8      this.startRefreshing();
 9    }
10  }
11
12  disconnect() {
13    this.stopRefreshing();
14  }
15
16  load() {
17    fetch(this.data.get('url'))
18      .then(response => response.text())
19      .then((html) => {
20        this.element.innerHTML = html;
21      });
22  }
23
24  startRefreshing() {
25    this.refreshTimer = setInterval(() => {
26      this.load();
27    }, this.data.get('refreshInterval'));
28  }
29
30  stopRefreshing() {
31    if (this.refreshTimer) {
32      clearInterval(this.refreshTimer);
33    }
34  }
35}