Fix several bugs related to the interaction between reactivity and imperative browser APIs

This commit is contained in:
daylily
2025-03-31 03:43:30 -04:00
parent 201a303168
commit 0e524a1309
3 changed files with 14 additions and 5 deletions
+3 -1
View File
@@ -32,8 +32,10 @@
})
hid.addEventListener('disconnect', e => {
if (device === e.device) {
toast.info('Device disconnected')
if (device === e.device) onchange(null)
onchange(null)
}
})
onMount(() => {
+5 -2
View File
@@ -52,7 +52,7 @@
async function renderPattern() {
if (imageBitmap === null) {
onchange(null)
renderedBitmap = null
return
}
@@ -71,12 +71,15 @@
const quantizedData = quantizer.reduce(ctx)
renderedBitmap = quantizedData
onchange(quantizedData)
}
$effect(() => {
renderPattern()
})
$effect(() => {
onchange(renderedBitmap)
})
</script>
<div class={cn('flex max-lg:flex-col gap-4', classNames)} {...restProps}>
+6 -2
View File
@@ -36,9 +36,13 @@
}
$effect(() => {
const context2x = freshContext(canvas2xEl)
const context1x = freshContext(canvas1xEl)
if (bitmap === null) return
drawQuantizedData(freshContext(canvas2xEl), bitmap)
drawQuantizedData(freshContext(canvas1xEl), bitmap)
drawQuantizedData(context2x, bitmap)
drawQuantizedData(context1x, bitmap)
})
</script>