Created
December 17, 2022 00:18
-
-
Save shugo/69184b738050cfa4fcafea963b73dfb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/browser.script.iife.js"></script> | |
<button id="start">Start</button> | |
<div id="counter">0</div> | |
<script type="text/ruby"> | |
require "js" | |
def start_counter | |
document = JS.global[:document] | |
counter = document.getElementById("counter") | |
10.times do |i| | |
p i | |
counter[:innerText] = i.to_s | |
p JS.eval('return new Promise((ok) => setTimeout(ok(42), 1000))').await | |
end | |
end | |
</script> | |
<script type="text/javascript"> | |
async function startCounter() { | |
window.rubyVM.evalAsync("start_counter") | |
} | |
var start = document.getElementById("start") | |
console.log(start) | |
start.addEventListener("click", () => { | |
startCounter() | |
}, false) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment