feat: add utility composable for polling values
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
readonly,
|
readonly,
|
||||||
Ref,
|
Ref,
|
||||||
ref,
|
ref,
|
||||||
|
shallowRef,
|
||||||
useContext,
|
useContext,
|
||||||
watch,
|
watch,
|
||||||
wrapProperty,
|
wrapProperty,
|
||||||
@@ -154,3 +155,26 @@ export function useToast() {
|
|||||||
const { $toast } = useContext()
|
const { $toast } = useContext()
|
||||||
return $toast
|
return $toast
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useColorMode() {
|
||||||
|
const { $colorMode } = useContext()
|
||||||
|
|
||||||
|
return $colorMode
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePolled<T>(
|
||||||
|
pollDurationMS: number,
|
||||||
|
pollFunc: () => T
|
||||||
|
): Ref<T> {
|
||||||
|
const result = shallowRef(pollFunc())
|
||||||
|
|
||||||
|
const handle = setInterval(() => {
|
||||||
|
result.value = pollFunc()
|
||||||
|
}, pollDurationMS)
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearInterval(handle)
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user