Closed inexorabletash closed 7 years ago
When I first wrote jslogo the interpreter was synchronous - every procedure ran to completion within a JS function call. That's now changed - procedures can return Promises, the modern async primitive for JS. That enables e.g. watching the turtle move during a procedure call. The stream functions - used by READWORD
etc - have not been updated and are still synchronous. They're implemented using the window.prompt()
function.
The prompt()
function and any other blocking call available to JS (sync XHR, alert(), showModalDialog(), etc) is basically deprecated in the web platform as the entire page must stop execution - animation needs to freeze, etc. In some browsers the prompt also blocks the whole browser, preventing the user from switching tabs.
Modern sites avoid these, and use custom UI implemented in HTML/CSS/JS. They are by necessity asynchronous.
Hence: (1) modify jslogo so that the stream functions are async (return a promise) and once that's done (2) switch from using prompt()
to a custom UI treatment for the user's input.
(Hopefully that clarifies this?)
Making stream.read
async is really simple - should just be a few minutes of work. It's replacing prompt()
that'll be somewhat time consuming since I don't want to pull in a dependency on any JS UI libraries.
Where is the code to change
For the first part, callers of stream.read in logo.js need to handle promises and the implementations of read() in index.js and the tests should return promises.
On Apr 30, 2017, at 12:39 PM, yamboy1 notifications@github.com wrote:
Where is the code to change
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
I made the async change. The remaining work is to replace window.prompt()
with custom UI.
Could you elaborate on this.