From a38c05febb853e13142b43efb4fab87e69f572f4 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Fri, 17 Dec 2021 14:42:13 +0530 Subject: [PATCH] feat: add utility composable for polling values --- .../helpers/utils/composables.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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( + pollDurationMS: number, + pollFunc: () => T +): Ref { + const result = shallowRef(pollFunc()) + + const handle = setInterval(() => { + result.value = pollFunc() + }, pollDurationMS) + + onBeforeUnmount(() => { + clearInterval(handle) + }) + + return result +}