Skip to content

Commit

Permalink
fix(useTimer): remaining after pause
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Apr 4, 2023
1 parent 453ff6c commit aafdfdb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/runtime/composables/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { ref, computed } from 'vue-demi'
import { useTimestamp } from '@vueuse/core'
import type { UseTimestampOptions } from '@vueuse/core'

export function useTimer (cb: (...args: unknown[]) => any, interval: number, options: UseTimestampOptions<true> = { controls: true }) {
export function useTimer (cb: (...args: unknown[]) => any, interval: number, options?: UseTimestampOptions<true>) {
let timer: number | null = null
const timestamp = useTimestamp(options)
const { pause: tPause, resume: tResume, timestamp } = useTimestamp({ ...(options || {}), controls: true })
const startTime = ref<number | null>(null)

const remaining = computed(() => {
if (!startTime.value) {
return
return 0
}
return interval - (timestamp.timestamp.value - startTime.value)
return interval - (timestamp.value - startTime.value)
})

function set (...args: unknown[]) {
Expand All @@ -38,18 +38,18 @@ export function useTimer (cb: (...args: unknown[]) => any, interval: number, opt

function stop () {
clear()
timestamp.pause()
tPause()
}

function pause () {
clear()
timestamp.pause()
tPause()
}

function resume () {
startTime.value = (startTime.value || 0) + (Date.now() - timestamp.timestamp.value)
timestamp.resume()
set()
tResume()
startTime.value = (startTime.value || 0) + (Date.now() - timestamp.value)
}

start()
Expand Down

1 comment on commit aafdfdb

@vercel
Copy link

@vercel vercel bot commented on aafdfdb Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxtlabs.vercel.app
nuxthq-ui.vercel.app
ui-git-dev-nuxtlabs.vercel.app

Please sign in to comment.