scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
94 lines • 2.76 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var timer_exports = {};
__export(timer_exports, {
MockTimer: () => MockTimer
});
module.exports = __toCommonJS(timer_exports);
var import_scriptable_abstract = require("scriptable-abstract");
class MockTimer extends import_scriptable_abstract.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 });
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockTimer
});
//# sourceMappingURL=timer.js.map