Commit 8610a80e authored by wildfirecode13's avatar wildfirecode13

1

parent d0e514e0
import EventEmitter from "./EventEmitter"; import EventEmitter from "./EventEmitter";
export default class Countdown extends EventEmitter<any> { export default class Countdown extends EventEmitter<any> {
_timer: any; private _timer;
_text: any; private _text;
_seconds: any; private _seconds;
_format: any; private _format;
_counter: any; private _counter;
_delay: any; private _delay;
_running: boolean; private _running;
constructor(text: any, seconds: any, format: any, delay: any); constructor(text: any, seconds: any, format: any, delay: any);
getCountdown(): string | undefined; private getCountdown;
getHHMMSS(): string; private getHHMMSS;
getMMSS(): string; private getMMSS;
getText(): any; private getText;
start(): void; start(): void;
stop(): void; private stop;
reset($seconds: number): void; reset($seconds: number): void;
set seconds(val: number);
get running(): boolean; get running(): boolean;
} }
...@@ -70,16 +70,12 @@ var Countdown = /** @class */ (function (_super) { ...@@ -70,16 +70,12 @@ var Countdown = /** @class */ (function (_super) {
this.emit("complete"); this.emit("complete");
}; };
Countdown.prototype.reset = function ($seconds) { Countdown.prototype.reset = function ($seconds) {
this.seconds = $seconds; this._seconds = $seconds;
}; };
Object.defineProperty(Countdown.prototype, "seconds", {
set: function (val) {
this._seconds = val;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Countdown.prototype, "running", { Object.defineProperty(Countdown.prototype, "running", {
// set seconds(val: number) {
// this._seconds = val;
// }
get: function () { get: function () {
return this._running; return this._running;
}, },
......
{ {
"name": "teddi", "name": "teddi",
"version": "1.0.4", "version": "1.0.5",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
......
...@@ -5,13 +5,13 @@ function getNum(n: any) { ...@@ -5,13 +5,13 @@ function getNum(n: any) {
} }
export default class Countdown extends EventEmitter<any> { export default class Countdown extends EventEmitter<any> {
_timer: any; private _timer: any;
_text: any; private _text: any;
_seconds: any; private _seconds: any;
_format: any; private _format: any;
_counter: any; private _counter: any;
_delay: any; private _delay: any;
_running = false; private _running = false;
constructor(text: any, seconds: any, format: any, delay: any) { constructor(text: any, seconds: any, format: any, delay: any) {
super(); super();
console.log(this); console.log(this);
...@@ -22,12 +22,12 @@ export default class Countdown extends EventEmitter<any> { ...@@ -22,12 +22,12 @@ export default class Countdown extends EventEmitter<any> {
this._delay = delay || 1000; this._delay = delay || 1000;
} }
getCountdown() { private getCountdown() {
if (this._format == "hhmmss") return this.getHHMMSS(); if (this._format == "hhmmss") return this.getHHMMSS();
if (this._format == "mmss") return this.getMMSS(); if (this._format == "mmss") return this.getMMSS();
} }
getHHMMSS() { private getHHMMSS() {
const left = this._seconds - this._counter; const left = this._seconds - this._counter;
const hours = Math.floor(left / 3600); const hours = Math.floor(left / 3600);
const minutes = Math.floor((left % 3600) / 60); const minutes = Math.floor((left % 3600) / 60);
...@@ -35,14 +35,14 @@ export default class Countdown extends EventEmitter<any> { ...@@ -35,14 +35,14 @@ export default class Countdown extends EventEmitter<any> {
return `${getNum(hours)}:${getNum(minutes)}:${getNum(seconds)}`; return `${getNum(hours)}:${getNum(minutes)}:${getNum(seconds)}`;
} }
getMMSS() { private getMMSS() {
const left = this._seconds - this._counter; const left = this._seconds - this._counter;
const minutes = Math.floor(left / 60); const minutes = Math.floor(left / 60);
const seconds = left % 60; const seconds = left % 60;
return `${getNum(minutes)}:${getNum(seconds)}`; return `${getNum(minutes)}:${getNum(seconds)}`;
} }
getText() { private getText() {
return this._text.replace("{0}", this.getCountdown()); return this._text.replace("{0}", this.getCountdown());
} }
...@@ -58,19 +58,19 @@ export default class Countdown extends EventEmitter<any> { ...@@ -58,19 +58,19 @@ export default class Countdown extends EventEmitter<any> {
}, this._delay); }, this._delay);
} }
stop() { private stop() {
this._running = false; this._running = false;
clearInterval(this._timer); clearInterval(this._timer);
this.emit("complete"); this.emit("complete");
} }
reset($seconds: number) { reset($seconds: number) {
this.seconds = $seconds; this._seconds = $seconds;
} }
set seconds(val: number) { // set seconds(val: number) {
this._seconds = val; // this._seconds = val;
} // }
get running() { get running() {
return this._running; return this._running;
......
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