-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Improve javascript execution #112
Comments
This code lead to the creation of #112. The use of on_page_ready callback is not "nice".
In 18b390c I made nicegui/tests/test_javascript.py Lines 24 to 26 in 18b390c
But on an async page, this could easily create a deadlock: @ui.page('/')
async def page():
ui.label('before js')
await ui.run_javascript('document.title = "A New Title"')
ui.label('after js') Therefore I changed the behaviour to raise an exception if javascript is requested to execute before the page is ready. |
The code to run JavaScript immediately after page is finished is not very nice. Due to the page handler we need to make internal objects available to the outside. See the map example: Lines 7 to 21 in ac5f8fd
Maybe the page builder could also be a generator. All code after |
I found a way to use the Lines 8 to 21 in c27ad19
|
I think we have two issues with the current javascript execution, which I put into one issue because of their interlocking:
1: unintuitive naming
We have two separate calls:
ui.run_javascript
to just execute andui.await_javascript
to get the value back. Both are awaitable. So the distinction is not self explaining. And writingmy_value = await ui.await_javascript(...)
is not nice.I suggest we merge both features into a single
ui.run_javascript
call. It always returns the data from the executed javascript which can also beNone
.2: silent ignore before page is ready
Calling
ui.run_javascript
before the page is ready is silently ignored. We could raise an Exception in this cases. But I'd rather make the javascript execute directly after page creation.The text was updated successfully, but these errors were encountered: