Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: add utility composable for polling values

Andrew Bastina38c05febb85
diff --git a/packages/hoppscotch-app/helpers/utils/composables.ts b/packages/hoppscotch-app/helpers/utils/composables.ts
index 482f35c8d..5f6baec59 100644
--- a/packages/hoppscotch-app/helpers/utils/composables.ts
+++ b/packages/hoppscotch-app/helpers/utils/composables.ts
@@ -5,6 +5,7 @@ import {
readonly,
Ref,
ref,
+ shallowRef,
useContext,
watch,
wrapProperty,
@@ -154,3 +155,26 @@ export function useToast() {
const { $toast } = useContext()
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
+}