Last active
May 23, 2016 17:12
-
-
Save tonyonodi/bcb9bcf5db5b7c91220ab20afe47a8f0 to your computer and use it in GitHub Desktop.
Attempt at implementing a js repl using es6 generators
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
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<!-- https://raw.githubusercontent.com/babel/babel/master/packages/babel-regenerator-runtime/runtime.js --> | |
<script src="http://codepen.io/anon/pen/BKXJKy.js"></script> | |
<ul id="console-outputs"></ul> | |
<form id="console-form"> | |
<input type="text" /> | |
</form> | |
<script> | |
function submitted() { | |
$("#console-form").on("submit", function(event) { | |
event.preventDefault(); | |
$("#console-form").off(); | |
const form = $(event.target); | |
const input = form.find('input'); | |
const inputVal = input.val(); | |
it.next(inputVal); | |
}); | |
} | |
function *main() { | |
const form = $("#console-form"); | |
const input = form.find('input'); | |
while(1) { | |
const inputVal = yield submitted(); | |
$("#console-outputs").append($(`<li>${eval(inputVal)}</li>`)); | |
input.val(""); | |
} | |
} | |
const it = main(); | |
it.next(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment