@revoloo/cypress6
Version:
Cypress.io end to end testing tool
45 lines (33 loc) • 833 B
JavaScript
import { observable, computed, action } from 'mobx'
import Timer from './duration-timer-model'
import dayjs from 'dayjs'
class TimerStore {
isRunning = false
timer
startTime
constructor (startTime) {
this.timer = new Timer()
this.startTime = dayjs(startTime)
}
get mainDisplay () {
return this.timer.display
}
measure () {
if (!this.isRunning) return
this.timer.milliseconds = dayjs().diff(this.startTime)
this.timerId = setTimeout(() => {
return this.measure()
}, 10)
}
startTimer () {
if (this.isRunning) return
this.isRunning = true
this.measure()
}
resetTimer () {
this.timer.reset()
this.isRunning = false
clearTimeout(this.timerId)
}
}
export default TimerStore