mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 06:13:35 +09:00
first
This commit is contained in:
25
sample/dev/talk/bundle/awesome-notifications-3.1.1/timer.js
Normal file
25
sample/dev/talk/bundle/awesome-notifications-3.1.1/timer.js
Normal file
@@ -0,0 +1,25 @@
|
||||
export default class {
|
||||
constructor(callback, delay) {
|
||||
this.callback = callback
|
||||
this.remaining = delay
|
||||
this.resume()
|
||||
}
|
||||
pause() {
|
||||
this.paused = true
|
||||
window.clearTimeout(this.timerId)
|
||||
this.remaining -= new Date() - this.start
|
||||
}
|
||||
resume() {
|
||||
this.paused = false
|
||||
this.start = new Date()
|
||||
window.clearTimeout(this.timerId)
|
||||
this.timerId = window.setTimeout(() => {
|
||||
window.clearTimeout(this.timerId)
|
||||
this.callback()
|
||||
}, this.remaining)
|
||||
}
|
||||
toggle() {
|
||||
if (this.paused) this.resume()
|
||||
else this.pause()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user