Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rror)
  • Loading branch information
ldemailly committed Sep 7, 2024
1 parent 2e2cbbc commit 094b321
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions _includes/grol_wasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
</style>
<script src="wasm_exec.js"></script>
<script>
function debounce(func) {
let timeout
return function (...args) {
const context = this
clearTimeout(timeout)
timeout = setTimeout(() => func.apply(context, args), 100) // 100ms debounce
}
}
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
Expand Down Expand Up @@ -106,10 +114,11 @@
resizeTextarea(document.getElementById('output'));
resizeTextarea(document.getElementById('errors'));
}
const debounceRun = debounce(run)
document.addEventListener('DOMContentLoaded', (event) => {
document.getElementById('input').addEventListener('keydown', function (e) {
if (e.key === 'Enter' && !isRunning) {
run();
debounceRun();
}
});
});
Expand All @@ -133,7 +142,8 @@
m={"str key": a, PI: "pi", 42: "str val", 1e3: "a lot"}</textarea>
</div>
<div>
Hit enter or click <button onClick="run();" id="runButton" disabled>Run</button> (will also format the code, also
Hit enter or click <button onClick="debounceRun()" id="runButton" disabled>Run</button> (will also format the code,
also
try <input type="checkbox" id="compact">compact)
<button id="addParamButton">Share</button>
<script>
Expand Down
Binary file modified grol.wasm
Binary file not shown.

0 comments on commit 094b321

Please sign in to comment.