New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Redraw once promise returned from event handler is settled #2862
base: next
Are you sure you want to change the base?
feat: Redraw once promise returned from event handler is settled #2862
Conversation
render/render.js
Outdated
if (this._ && ev.redraw !== false) { | ||
(0, this._)() | ||
if (result != null) { | ||
if (typeof result.finally === "function") result.finally((0, this._)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just use .then
. It's redundant to do both that and .finally
, because per spec p.finally(f)
is roughly just .then(async v => { await f(); return v }, async e => { await f(); throw e })
, complete with the .then
method call being observable.
render/render.js
Outdated
(0, this._)() | ||
if (result != null) { | ||
if (typeof result.finally === "function") result.finally((0, this._)) | ||
else if (typeof result.then === "function") result.then((0, this._)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Your
(0, expr)
is redundant. It's not immediately called, so it does nothing. - Let's do it even on error, similarly to my above
finally
to ensure errors get reported correctly. (Obviously, you can't useasync
/await
, but it's fairly straightforward.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I was not sure about the use of this
(0, expr)
so I've tried to keep it consistent. I'm gonna callthis._
directly. - Not sure what you mean by "my above
finally
" but I guess I can just passthis._
to bothresolve
andreject
callbacks ofthen
, like this:
if (result != null && typeof result.then === "function") result.then(this._, this._)
I just need to update it with the tests as it seems to work as expected. Thank you!
Let me know if there's anything more I have to do. I've applied the requested changes. |
Description
In this PR I'm proposing a solution to handle async event handlers.
I've decided to duck-type for
finally
with fallback tothen
. I assume we still want to redraw on rejected promise.NOTE: seems like
onbeforeremove
lifecycle event handler is also dealing with promises so maybe some common logic can be extracted.Motivation and Context
I think it's reasonable to redraw after asynchronous action is finished (resulting from user action). I was surprised it doesn't work like that and seems like it can!
More details in the issue here: #2861
How Has This Been Tested?
It seems to work according to my manual testing and it doesn't fail any existing tests.
I'm marking it as a draft as I still need to work out how to make tests work for asynchronous code. Some help would be appreciated. I will hopefully include them soon.Solved.Types of changes
Checklist:
docs/changelog.md
EDIT: Updated
docs
. I'm not sure how I'm supposed to update changelog, as it seems like it was not updated recently.EDIT2: Added tests. Let me know if they are not sufficient.