@exmg/lit-controllers
Version:
Exmg Lit Controllers
31 lines • 942 B
JavaScript
export class IntervalController {
constructor(host, { callback, mode, timer }) {
this._timer = 5000;
this._mode = 'AUTO';
(this._host = host).addController(this);
this._mode = mode !== null && mode !== void 0 ? mode : this._mode;
this._timer = timer !== null && timer !== void 0 ? timer : this._timer;
this._callback = callback || null;
}
startInterval() {
clearInterval(this._timer);
if (this._callback) {
this._callback();
this._timerRef = setInterval(() => {
this._callback && this._callback();
}, this._timer);
}
}
stopInterval() {
clearInterval(this._timerRef);
}
hostConnected() {
if (this._mode === 'AUTO') {
this.startInterval();
}
}
hostDisconnected() {
clearInterval(this._timerRef);
}
}
//# sourceMappingURL=interval.js.map