From d3579b5d8625222ccdfd1c39c4df5688f4de0d0d Mon Sep 17 00:00:00 2001 From: Kevin Beier Date: Sun, 28 May 2023 16:44:37 +0200 Subject: [PATCH 1/2] cleaner overall composable conventions --- src/components/LogOutput/LogOutput.vue | 14 +++--- .../MainVideoStream/MainVideoStream.vue | 7 ++- src/components/Navigation/Navigation.vue | 26 +++-------- .../useForceRerender/useForceRerender.test.ts | 9 ++-- .../useForceRerender/useForceRerender.ts | 27 +++++++----- src/composables/useRunning/useRunning.ts | 18 +++++--- src/views/CapturePage.vue | 43 +++++------------- src/views/RegexView.vue | 44 ++++++------------- 8 files changed, 77 insertions(+), 111 deletions(-) diff --git a/src/components/LogOutput/LogOutput.vue b/src/components/LogOutput/LogOutput.vue index 34c1a81..4294dad 100644 --- a/src/components/LogOutput/LogOutput.vue +++ b/src/components/LogOutput/LogOutput.vue @@ -9,15 +9,11 @@ - {{ item.timestamp }} + {{ item.timestamp }}
Element: {{ item.match.element }}
Rating: {{ item.rating }}
@@ -29,12 +25,15 @@ diff --git a/src/composables/useForceRerender/useForceRerender.test.ts b/src/composables/useForceRerender/useForceRerender.test.ts index 989682e..a7450bc 100644 --- a/src/composables/useForceRerender/useForceRerender.test.ts +++ b/src/composables/useForceRerender/useForceRerender.test.ts @@ -1,12 +1,11 @@ import { describe, it, expect } from 'vitest'; import { mount } from '@vue/test-utils'; -import { - useForceRerender, - isRerendering, -} from '@/composables/useForceRerender/useForceRerender'; +import useForceRerender from '@/composables/useForceRerender/useForceRerender'; describe('useForceRerender Composable', () => { it('should trigger a rerender when called', async () => { + const { isRerendering, forceRerender } = useForceRerender(); + const text = 'Component to rerender'; const wrapper = mount({ @@ -23,7 +22,7 @@ describe('useForceRerender Composable', () => { }); // Call the useForceRerender composable - await useForceRerender(); + await forceRerender(); // Check that the component has rerendered expect(wrapper.text()).toBe(text); diff --git a/src/composables/useForceRerender/useForceRerender.ts b/src/composables/useForceRerender/useForceRerender.ts index 7ede455..4de4fe3 100644 --- a/src/composables/useForceRerender/useForceRerender.ts +++ b/src/composables/useForceRerender/useForceRerender.ts @@ -3,20 +3,27 @@ import { nextTick, ref } from 'vue'; /** * Reactive boolean that can be used to force a component to rerender. */ -export const isRerendering = ref(true); +const isRerendering = ref(true); /** * Tries to rerender the component by removing it from the DOM and adding it back in. * - * Only works if the compnent has a v-if="rerender" directive. active + * Only works if the component has a v-if="rerender" directive. */ -export const useForceRerender = async () => { - // Remove component from the DOM - isRerendering.value = false; +export default function useForceRerender() { + const forceRerender = async () => { + // Remove component from the DOM + isRerendering.value = false; - // Wait for the change to get flushed to the DOM - await nextTick(); + // Wait for the change to get flushed to the DOM + await nextTick(); - // Add the component back in - isRerendering.value = true; -}; + // Add the component back in + isRerendering.value = true; + }; + + return { + forceRerender, + isRerendering, + }; +} diff --git a/src/composables/useRunning/useRunning.ts b/src/composables/useRunning/useRunning.ts index c14baf8..ba4f831 100644 --- a/src/composables/useRunning/useRunning.ts +++ b/src/composables/useRunning/useRunning.ts @@ -5,15 +5,18 @@ import useNotificationSystem from '@/composables/useNotificationSystem/useNotifi /** * Reactive boolean that can be used to check the capture status. */ -export const isRunning = ref(false); +const isRunning = ref(false); /** * Function that can be used to start and stop the capturing. */ -export const useRunning = () => { +export default function useRunning() { const vigad = Vigad.getInstance(); - const start = () => { + /** + * Start capturing. + */ + const start = (): void => { isRunning.value = true; vigad.startTesseract(); useNotificationSystem().createNotification({ @@ -22,13 +25,16 @@ export const useRunning = () => { }); }; - const stop = () => { + /** + * Stop capturing. + */ + const stop = (): void => { isRunning.value = false; vigad.stopTesseract(); useNotificationSystem().createWarningNotification({ title: 'Stopped Capturing', message: 'Capturing was stopped' - }) + }); }; return { @@ -36,4 +42,4 @@ export const useRunning = () => { start, stop, }; -}; +} diff --git a/src/views/CapturePage.vue b/src/views/CapturePage.vue index 18bc024..83cf23c 100644 --- a/src/views/CapturePage.vue +++ b/src/views/CapturePage.vue @@ -1,39 +1,16 @@