uicore-ts
Version:
UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha
93 lines (37 loc) • 1.09 kB
text/typescript
const YES = true
const NO = false
export class UITimer {
_intervalID!: number
isValid: boolean = YES
constructor(public interval: number, public repeats: boolean, public target: Function) {
this.schedule()
}
schedule() {
const callback = () => {
if (this.repeats == NO) {
this.invalidate()
}
this.target()
}
this._intervalID = window.setInterval(callback, this.interval * 1000)
}
reschedule() {
this.invalidate()
this.schedule()
}
fire() {
if (this.repeats == NO) {
this.invalidate()
}
else {
this.reschedule()
}
this.target()
}
invalidate() {
if (this.isValid) {
clearInterval(this._intervalID)
this.isValid = NO
}
}
}