scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
72 lines • 1.76 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { AbsTimer } from "scriptable-abstract";
class MockTimer extends AbsTimer {
constructor() {
super({
timeInterval: 0,
repeats: false,
running: false
});
__publicField(this, "timerId", null);
}
/**
* Schedule a function to be called after a delay
* @param callback Function to be called
*/
schedule(callback) {
const ms = this.timeInterval * 1e3;
if (this.repeats) {
this.timerId = setInterval(callback, ms);
} else {
this.timerId = setTimeout(callback, ms);
}
this.setState({ running: true });
}
/**
* Invalidates the timer, preventing it from firing
*/
invalidate() {
if (this.timerId) {
clearTimeout(this.timerId);
clearInterval(this.timerId);
this.timerId = null;
}
this.setState({ running: false });
}
/**
* Whether the timer is currently running
*/
get isRunning() {
return this.state.running;
}
/**
* Time interval in seconds
*/
get timeInterval() {
return this.state.timeInterval;
}
/**
* Sets the time interval in seconds
*/
set timeInterval(value) {
this.setState({ timeInterval: value });
}
/**
* Whether the timer repeats
*/
get repeats() {
return this.state.repeats;
}
/**
* Sets whether the timer repeats
*/
set repeats(value) {
this.setState({ repeats: value });
}
}
export {
MockTimer
};
//# sourceMappingURL=timer.js.map