4 ms·
Thanks! Re: nicegui, I like nicegui. Hyperdiv and nicegui are similar in that they're "build web UIs in Python" frameworks but take significantly different app
by mondrian 3y ago
Thanks!
Re: nicegui, I like nicegui. Hyperdiv and nicegui are similar in that they're "build web UIs in Python" frameworks but take significantly different approaches. See this comment: https://news.ycombinator.com/item?id=39458641 https://news.ycombinator.com/item?id=39458641
Re: async. Hyperdiv's main function, which generates the UI, runs synchronously, indeed. But the main function can spawn off asynchronous calls. For example:
async def api_call():
data = await get_data()
return data
def main():
task = hd.task()
task.run(api_call)
if not task.done:
hd.spinner()
else:
hd.text("Loaded data:", task.result)
This app spins off an async call to api_call(). While the call is running in the background, a loading spinner is displayed. When the task finishes, its return value is rendered.
Async tasks can also update state gradually while they run:
async def api_calls(state):
data1 = await get_data1()
state.data1 = data1
data2 = await get_data2()
state.data2 = data2
def main():
state = hd.state(data1=None, data2=None)
task = hd.task()
task.run(api_calls, state)
hd.text("Data1:", state.data1)
hd.text("Data2:", state.data2)
This app will initially display "Data1: None\nData2: None". When get_data1() finishes running, the UI updates to show the result for "Data1", but the result for "Data2" is still None. When `get_data2()` finishes running, both fields are then filled.
You can also write an async function that runs indefinitely, continually listening on some I/O channel and updating state as new data arrives. When the app exits, it can signal the task to exit.
- luke-stanley 3y agoThat's cool and I imagine it supports a lot of the situations async users would need. Thanks for your great explanation. Having a more clean, declarative state is a great differentiation from Nicegui. This is a great contribution, I wish you the best of luck to you!