refactor: merge watch targets, flatten callback (#812)

This commit is contained in:
藍+85CD
2025-12-17 19:34:25 +08:00
committed by GitHub
parent 263e1849a6
commit f16a0c102f
5 changed files with 7 additions and 13 deletions
@@ -18,9 +18,7 @@ onMounted(() => {
handleAnalyze()
})
watch(() => props.stream, () => {
handleAnalyze()
})
watch(() => props.stream, handleAnalyze)
function handleAnalyze() {
if (!props.stream) {
@@ -42,10 +42,9 @@ function scrollToBottom() {
})
}
watch(() => props.messages, () => scrollToBottom(), { deep: true, flush: 'post' })
watch(() => props.streamingMessage, () => scrollToBottom(), { deep: true, flush: 'post' })
watch(() => props.sending, () => scrollToBottom(), { flush: 'post' })
onMounted(() => scrollToBottom())
watch([() => props.messages, () => props.streamingMessage], scrollToBottom, { deep: true, flush: 'post' })
watch(() => props.sending, scrollToBottom, { flush: 'post' })
onMounted(scrollToBottom)
const streaming = computed<ChatAssistantMessage>(() => props.streamingMessage ?? { role: 'assistant', content: '', slices: [], tool_results: [] })
const showStreamingPlaceholder = computed(() => (streaming.value.slices?.length ?? 0) === 0 && !streaming.value.content)
@@ -37,9 +37,7 @@ function initializeForm() {
}
// Watch for provider changes
watch(() => context.selectedProvider.value?.id, () => {
initializeForm()
})
watch(() => context.selectedProvider.value?.id, initializeForm)
// Computed properties
const needsApiKey = computed(() => {
@@ -65,8 +65,7 @@ function handleResize() {
// The CSS styles handle the display size, so we don't need to manually set view dimensions
}
watch([() => props.width, () => props.height], () => handleResize())
watch(() => props.resolution, () => handleResize())
watch([() => props.width, () => props.height, () => props.resolution], handleResize)
onMounted(async () => containerRef.value && await initLive2DPixiStage(containerRef.value))
onUnmounted(() => pixiApp.value?.destroy())
@@ -393,7 +393,7 @@ function updateDropShadowFilter() {
model.value.filters = [dropShadowFilter.value]
}
watch([() => props.width, () => props.height], () => handleResize())
watch([() => props.width, () => props.height], handleResize)
watch(modelSrcRef, async () => await loadModel(), { immediate: true })
watch(dark, updateDropShadowFilter, { immediate: true })
watch([model, themeColorsHue], updateDropShadowFilter)