fix(timer): now wait for the correct duration

This commit is contained in:
wryk 2019-04-26 22:17:35 +02:00
parent b416ec47f3
commit 6daaa915ae
3 changed files with 19 additions and 31 deletions

View file

@ -25,48 +25,41 @@ class Countdown extends EventEmitter {
if (!this._running && !this._started) { if (!this._running && !this._started) {
this._running = true this._running = true
this._started = true this._started = true
this.emit('started') this.emit('started')
this._update()
this.emit('progress', 0) this._intervalId = setInterval(() => {
this.emit('update', this._n) this._count++
this._update()
this._intervalId = setInterval(() => this._update(), this._delay) if (this._count >= this._n) {
this._cleanup()
this.done = true
this.emit('done')
this._end()
}
}, this._delay)
} }
} }
cancel () { cancel () {
if (this._running && !this._ended) { if (this._running && !this._ended) {
this._cleanup() this._cleanup()
this._cancelled = true this._cancelled = true
this.emit('cancelled') this.emit('cancelled')
this._end()
this.ended = true
this.emit('ended')
this.running = false
} }
} }
_update () { _update () {
if (this._running) { this.emit('progress', this._count / this._n)
if (this._count < this._n) { this.emit('update', this._n - this._count)
this._count++ }
this.emit('progress', this._count / this._n)
this.emit('update', this._n - this._count)
} else {
this._cleanup()
this.done = true _end () {
this.emit('done') this.ended = true
this.emit('ended')
this.ended = true this._running = false
this.emit('ended')
this.running = false
}
}
} }
_cleanup () { _cleanup () {

View file

@ -31,7 +31,6 @@ export default new Vuex.Store({
state.boomerang = value state.boomerang = value
}, },
updateTimer (state, value) { updateTimer (state, value) {
console.log(typeof value)
state.timer = value state.timer = value
}, },
updateCamera (state, camera) { updateCamera (state, camera) {

View file

@ -104,10 +104,6 @@ export default {
this.countdown = null this.countdown = null
}) })
this.countdown.on('cancelled', () => {
console.log('cancelled')
})
this.countdown.on('done', () => { this.countdown.on('done', () => {
this.runCapture() this.runCapture()
}) })