Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed May 17, 2023
1 parent 0801e79 commit 05b729e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/frontend/src/components/MkImgWithBlurhash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ watch([() => props.width, () => props.height, root], () => {
immediate: true,
});
workerPromise.then(worker => {
if (!worker) return;
worker.postMessage({
id: viewId,
hash: props.hash,
});
worker.addEventListener('message', event => {
if (event.data.id !== viewId) return;
drawImage(event.data.bitmap as ImageBitmap);
});
});
function drawImage(bitmap: CanvasImageSource) {
// canvasがない(mountedされていない)場合はTmpに保存しておく
if (!canvas.value) {
Expand Down Expand Up @@ -165,6 +151,19 @@ async function draw() {
}
}
function workerOnMessage(event: MessageEvent) {
if (event.data.id !== viewId) return;
drawImage(event.data.bitmap as ImageBitmap);
}
workerPromise.then(worker => {
if (worker) {
worker.addEventListener('message', workerOnMessage);
}
draw();
});
watch(() => props.src, () => {
waitForDecode();
});
Expand All @@ -181,7 +180,11 @@ onMounted(() => {
});
onUnmounted(() => {
workerPromise.then(worker => worker?.postMessage!({ id: viewId, delete: true }));
workerPromise.then(worker => {
if (worker) {
worker.removeEventListener('message', workerOnMessage);
}
});
});
</script>
Expand Down

0 comments on commit 05b729e

Please sign in to comment.