Commit f1c68996 authored by wildfirecode13's avatar wildfirecode13

1

parent 9a51e95a
import EventEmitter from "../EventEmitter";
export default class Timer extends EventEmitter<any> {
_running: boolean;
repeatCount: any;
delay: any;
currentCount: any;
_timer: any;
constructor(repeatCount: any, delay?: number);
start(): void;
stop(): void;
reset(): void;
}
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var EventEmitter_1 = require("../EventEmitter");
var Timer = /** @class */ (function (_super) {
__extends(Timer, _super);
function Timer(repeatCount, delay) {
if (delay === void 0) { delay = 1000; }
var _this = _super.call(this) || this;
_this._running = false;
_this.repeatCount = repeatCount;
_this.delay = delay;
_this.currentCount = 0;
return _this;
}
Timer.prototype.start = function () {
var _this = this;
this._running = true;
this._timer = setInterval(function () {
_this.currentCount++;
if (_this.currentCount == _this.repeatCount) {
_this.stop();
_this.emit('complete');
}
}, this.delay);
};
Timer.prototype.stop = function () {
this._running = false;
clearInterval(this._timer);
};
Timer.prototype.reset = function () {
this.stop();
this.currentCount = 0;
this.start();
};
return Timer;
}(EventEmitter_1.default));
exports.default = Timer;
{
"name": "teddi",
"version": "1.0.8",
"version": "1.0.9",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
import EventEmitter from "../EventEmitter";
export default class Timer extends EventEmitter<any> {
_running=false;
repeatCount;
delay;
currentCount;
_timer
constructor(repeatCount, delay = 1000) {
super();
this.repeatCount = repeatCount;
this.delay = delay;
this.currentCount = 0;
}
start() {
this._running = true;
this._timer = setInterval(() => {
this.currentCount++;
if (this.currentCount == this.repeatCount) {
this.stop();
this.emit('complete');
}
}, this.delay);
}
stop() {
this._running=false;
clearInterval(this._timer);
}
reset() {
this.stop();
this.currentCount = 0;
this.start();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment