From 9c56b4ddb54a50dbfa2e1d2571a0123b0ffac3f7 Mon Sep 17 00:00:00 2001 From: Kasper Date: Tue, 17 Jun 2025 08:41:41 +0200 Subject: [PATCH] Fix website output --- web/src/routes/+page.svelte | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte index 759c363..cf7850f 100644 --- a/web/src/routes/+page.svelte +++ b/web/src/routes/+page.svelte @@ -10,17 +10,19 @@ cpc = mod; }); - let input = $state(""); - let output = $derived.by(() => { + function wasm_eval(input: string) { + if (!cpc || input.trim().length === 0) { + return ""; + } try { - if (!cpc || input.trim().length === 0) { - return ""; - } return cpc.wasm_eval(input); } catch (e) { return ""; } - }); + } + + let input = $state(""); + let output = $derived(wasm_eval(input)); let saved_queries: { id: number; in: string; out: string }[] = $state([]); @@ -62,22 +64,18 @@ type="text" class="border border-gray-500/50 w-full rounded-lg px-3 py-2 outline-none" bind:value={input} - onkeydown={(e) => { + onkeydown={async (e) => { + const input_el = e.currentTarget; + const input = e.currentTarget.value; if (check_shortcut(e, "Enter")) { - const input = e.currentTarget.value; - let out; - try { - out = wasm_eval(e.currentTarget.value); - } catch (e) { - out = ""; - } + const out = wasm_eval(input) console.log(out); saved_queries.unshift({ id: saved_queries.length, in: input, out, }); - e.currentTarget.value = ""; + input_el.value = ""; output = ""; } }}