view.py icon indicating copy to clipboard operation
view.py copied to clipboard

Advanced Components API

Open ZeroIntensity opened this issue 2 years ago • 2 comments

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?

ZeroIntensity avatar Aug 17 '23 14:08 ZeroIntensity

Need an API designed for this. Perhaps it could be with the component system?

ZeroIntensity avatar Nov 16 '23 18:11 ZeroIntensity

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")))

ZeroIntensity avatar Nov 25 '23 21:11 ZeroIntensity