view.py
view.py copied to clipboard
Advanced Components API
As of now, the global attributes on components don't support things like events because there's no way to run Python in the browser. We could use #11 as a solution, but that might take a while, so this could be introduced in the meantime.
Possibly use a config option?
Need an API designed for this. Perhaps it could be with the component system?
Current API. Will need to change some of the component API in order to make this nice.
@app.get("/")
async def index():
btn = button("click me!")
count = 0
@btn.event("click")
def browser():
# this code is shipped to the browser
nonlocal count
count += 1
return page(div(btn, p(f"you clicked {count} times")))