From aafdfdb59c365c542f93703dd52b4306ac935040 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 4 Apr 2023 13:36:24 +0200 Subject: [PATCH] fix(useTimer): remaining after pause --- src/runtime/composables/useTimer.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/runtime/composables/useTimer.ts b/src/runtime/composables/useTimer.ts index 7f4c0095f5..f8a180f79c 100644 --- a/src/runtime/composables/useTimer.ts +++ b/src/runtime/composables/useTimer.ts @@ -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 = { controls: true }) { +export function useTimer (cb: (...args: unknown[]) => any, interval: number, options?: UseTimestampOptions) { let timer: number | null = null - const timestamp = useTimestamp(options) + const { pause: tPause, resume: tResume, timestamp } = useTimestamp({ ...(options || {}), controls: true }) const startTime = ref(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[]) { @@ -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()