mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 06:51:46 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ecd7cefde | ||
|
|
aafdfdb59c |
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
### [1.2.7](https://github.com/nuxtlabs/ui/compare/v1.2.6...v1.2.7) (2023-04-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **useTimer:** remaining after pause ([aafdfdb](https://github.com/nuxtlabs/ui/commit/aafdfdb59c365c542f93703dd52b4306ac935040))
|
||||||
|
|
||||||
### [1.2.6](https://github.com/nuxtlabs/ui/compare/v1.2.5...v1.2.6) (2023-04-04)
|
### [1.2.6](https://github.com/nuxtlabs/ui/compare/v1.2.5...v1.2.6) (2023-04-04)
|
||||||
|
|
||||||
### [1.2.5](https://github.com/nuxtlabs/ui/compare/v1.2.4...v1.2.5) (2023-04-04)
|
### [1.2.5](https://github.com/nuxtlabs/ui/compare/v1.2.4...v1.2.5) (2023-04-04)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nuxthq/ui",
|
"name": "@nuxthq/ui",
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"repository": "https://github.com/nuxtlabs/ui",
|
"repository": "https://github.com/nuxtlabs/ui",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ import { ref, computed } from 'vue-demi'
|
|||||||
import { useTimestamp } from '@vueuse/core'
|
import { useTimestamp } from '@vueuse/core'
|
||||||
import type { UseTimestampOptions } 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
|
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 startTime = ref<number | null>(null)
|
||||||
|
|
||||||
const remaining = computed(() => {
|
const remaining = computed(() => {
|
||||||
if (!startTime.value) {
|
if (!startTime.value) {
|
||||||
return
|
return 0
|
||||||
}
|
}
|
||||||
return interval - (timestamp.timestamp.value - startTime.value)
|
return interval - (timestamp.value - startTime.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
function set (...args: unknown[]) {
|
function set (...args: unknown[]) {
|
||||||
@@ -38,18 +38,18 @@ export function useTimer (cb: (...args: unknown[]) => any, interval: number, opt
|
|||||||
|
|
||||||
function stop () {
|
function stop () {
|
||||||
clear()
|
clear()
|
||||||
timestamp.pause()
|
tPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause () {
|
function pause () {
|
||||||
clear()
|
clear()
|
||||||
timestamp.pause()
|
tPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
function resume () {
|
function resume () {
|
||||||
startTime.value = (startTime.value || 0) + (Date.now() - timestamp.timestamp.value)
|
|
||||||
timestamp.resume()
|
|
||||||
set()
|
set()
|
||||||
|
tResume()
|
||||||
|
startTime.value = (startTime.value || 0) + (Date.now() - timestamp.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|||||||
Reference in New Issue
Block a user