-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
webxdc api: Await calls to setUpdateListener() callback #4537
base: main
Are you sure you want to change the base?
Conversation
This allows an async callback to be passed to webxdc.setUpdateListener()
The change makes sense to me. The webxdc API is not precise on the callback. In https://webxdc.org/docs/spec/setUpdateListener.html it says @r10s Looking at Android https://github.com/deltachat/deltachat-android/blob/main/src/main/res/raw/webxdc.js the callback is called without await. So if we fix that in Desktop it should be updated there too. And maybe update the API: |
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.
- As @nicodh said, the spec needs to be updated.
- This is gonna be a breaking change for the apps. Need to consider how we want to handle this fact. One hypothetical situation where it's breaking is where one async update listener call awaits for another update listener call.
- Although this is also true for the current version of the webxdc spec, we probably need to say what should happen when an error occurs in the listener, or when the promise (thenable) rejects.
I made a pr to the types repo with todo where else it needs to be changed: webxdc/webxdc-types#13 |
@ralphtheninja can you add to the initial PR description why this change is needed and what is now possible what was not possible before. esp. as this change requires quite some upfollownings and the impact to existing webxdc apps seems not 100% clear also, this should not go to current release |
@r10s I've updated the PR text to show more what the problem is. |
It's not really clear to me if just awaiting is good enough. What happens if the callback throws etc? This should be tested also. So maybe let this PR hang a bit here a while. |
Side note but related: Can the listener in |
This allows an async callback to be passed to
webxdc.setUpdateListener()
.Let me illustrate with an example by taking the simplest example from the webxdc.org page and tweaking it a bit. So imagine this app:
It allows you to input numbers but only shows the ones you haven't already put in. So you can type like
1
and hit send a couple of times, then you just see a single1
, then you type a2
maybe and hit send a couple of times. It works.Now, when you refresh the browser, it'll show everything you have put in. This means you can't have local state (this is just a javascript array) and do something async while updating that state (exemplified by
somethingReallyAsync()
).If you instead
await callback()
this works.Note that if you run this in the browser and you're using the local
webxdc.js
variant, thesetUpdateListener
method needs to change to something like: