6269f3c47e
https://app.fizzy.do/5986089/cards/2743 It includes a debounce interval to avoid too many of these.
22 lines
462 B
JavaScript
22 lines
462 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class extends Controller {
|
|
static values = {
|
|
reloadInterval: { type: Number, default: 10 * 60 } // 10 minutes
|
|
}
|
|
|
|
connect() {
|
|
this.freshSince = Date.now()
|
|
}
|
|
|
|
reload() {
|
|
const now = Date.now()
|
|
const reloadIntervalMs = this.reloadIntervalValue * 1000
|
|
|
|
if ((now - this.freshSince) >= reloadIntervalMs) {
|
|
this.freshSince = now
|
|
this.element.reload()
|
|
}
|
|
}
|
|
}
|