Open joshuahhh opened 3 years ago
This is rad! Thank you for working on this fix ✨
Hi @samdenty! Have you had a chance to look at this? I'd much appreciate your feedback. Thanks!
Just wanted to bump this PR 😄 It would be great to fix this! FYI this bug is reproducible on CodeSandbox and the p5.js Editor.
Problem
Because console-feed runs console methods in
setTimeout
, it cannot capture changes happening synchronously between logs. For instance,will log:
I believe this
setTimeout
was added for performance reasons. I'm sure that's preferable for some use-cases, but for other use-cases, it is confusing and certainly not ideal. (For example: https://github.com/processing/p5.js-web-editor/issues/1203#issuecomment-629722076.)I believe this issue is the root cause of #23 & #66.
Possible solution
I don't know the details of the performance issues the
setTimeout
was added to mitigate. It's possible thesetTimeout
should simply be removed.If not, then it would be great if this behavior could be customizable. In this PR, I add a new option called
async
toHook
. By default,async
istrue
, reproducing the current behavior. But ifasync
is set tofalse
, thesetTimeout
is replaced with immediate execution of its contents.Hook
already has a single boolean argument to controlencode
. Having multiple boolean arguments results in less-readable code, so I replaced this with an options object. (For backwards-compatibility, a user can still just pass in a single boolean forencode
.)Please let me know what you think of this approach! I'd be happy to make changes depending on what you think is best.
Thanks a bunch!