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 => { hid.addEventListener('disconnect', e => {
if (device === e.device) {
toast.info('Device disconnected') toast.info('Device disconnected')
if (device === e.device) onchange(null) onchange(null)
}
}) })
onMount(() => { onMount(() => {
+5 -2
View File
@@ -52,7 +52,7 @@
async function renderPattern() { async function renderPattern() {
if (imageBitmap === null) { if (imageBitmap === null) {
onchange(null) renderedBitmap = null
return return
} }
@@ -71,12 +71,15 @@
const quantizedData = quantizer.reduce(ctx) const quantizedData = quantizer.reduce(ctx)
renderedBitmap = quantizedData renderedBitmap = quantizedData
onchange(quantizedData)
} }
$effect(() => { $effect(() => {
renderPattern() renderPattern()
}) })
$effect(() => {
onchange(renderedBitmap)
})
</script> </script>
<div class={cn('flex max-lg:flex-col gap-4', classNames)} {...restProps}> <div class={cn('flex max-lg:flex-col gap-4', classNames)} {...restProps}>
+6 -2
View File
@@ -36,9 +36,13 @@
} }
$effect(() => { $effect(() => {
const context2x = freshContext(canvas2xEl)
const context1x = freshContext(canvas1xEl)
if (bitmap === null) return if (bitmap === null) return
drawQuantizedData(freshContext(canvas2xEl), bitmap)
drawQuantizedData(freshContext(canvas1xEl), bitmap) drawQuantizedData(context2x, bitmap)
drawQuantizedData(context1x, bitmap)
}) })
</script> </script>