Skip to content

Commit ba3ff86

Browse files
debounce edit event
1 parent 7bff1c2 commit ba3ff86

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

index.html

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
<h1>Schemascii Playground</h1>
3535
<div class="flex row">
3636
<div class="flex column">
37-
<div class="flex row">
38-
<p style="flex: 3">Schemascii Source</p>
39-
<button id="render" style="flex: 1">Render</button>
40-
</div><textarea id="schemascii"></textarea>
37+
<p>Schemascii Source</p><textarea id="schemascii"></textarea>
4138
</div>
4239
<div class="flex column">
4340
<p>CSS</p><textarea id="css"></textarea>
@@ -89,15 +86,19 @@ <h1>Schemascii Playground</h1>
8986
css.addEventListener("input", () => {
9087
style_elem.innerHTML = css.value;
9188
});
92-
render_button.addEventListener("click", async () => {
93-
console.textContent = "";
94-
errors.textContent = "";
95-
try {
96-
output.innerHTML = await schemascii.render("playground", source.value);
97-
} catch (e) {
98-
error(`\nJS Error:\n${e.stack}\n`);
99-
throw e;
100-
}
89+
var timeout = null;
90+
source.addEventListener("input", () => {
91+
if (timeout) clearTimeout(timeout);
92+
setTimeout(async () => {
93+
console.textContent = "";
94+
errors.textContent = "";
95+
try {
96+
output.innerHTML = await schemascii.render("playground", source.value);
97+
} catch (e) {
98+
error(`\nJS Error:\n${e.stack}\n`);
99+
throw e;
100+
}
101+
}, 500);
101102
});
102103
}
103104
main();

0 commit comments

Comments
 (0)