Skip to content

Commit 9c56b4d

Browse files
Fix website output
1 parent 9b49d8c commit 9c56b4d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

web/src/routes/+page.svelte

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
cpc = mod;
1111
});
1212
13-
let input = $state("");
14-
let output = $derived.by(() => {
13+
function wasm_eval(input: string) {
14+
if (!cpc || input.trim().length === 0) {
15+
return "";
16+
}
1517
try {
16-
if (!cpc || input.trim().length === 0) {
17-
return "";
18-
}
1918
return cpc.wasm_eval(input);
2019
} catch (e) {
2120
return "";
2221
}
23-
});
22+
}
23+
24+
let input = $state("");
25+
let output = $derived(wasm_eval(input));
2426
let saved_queries: { id: number; in: string; out: string }[] = $state([]);
2527
</script>
2628

@@ -62,22 +64,18 @@
6264
type="text"
6365
class="border border-gray-500/50 w-full rounded-lg px-3 py-2 outline-none"
6466
bind:value={input}
65-
onkeydown={(e) => {
67+
onkeydown={async (e) => {
68+
const input_el = e.currentTarget;
69+
const input = e.currentTarget.value;
6670
if (check_shortcut(e, "Enter")) {
67-
const input = e.currentTarget.value;
68-
let out;
69-
try {
70-
out = wasm_eval(e.currentTarget.value);
71-
} catch (e) {
72-
out = "";
73-
}
71+
const out = wasm_eval(input)
7472
console.log(out);
7573
saved_queries.unshift({
7674
id: saved_queries.length,
7775
in: input,
7876
out,
7977
});
80-
e.currentTarget.value = "";
78+
input_el.value = "";
8179
output = "";
8280
}
8381
}}

0 commit comments

Comments
 (0)