widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.62k stars 105 forks source link

feat: reactive_task decorator (re)runs a task when a dependency changes #473

Open maartenbreddels opened 4 months ago

maartenbreddels commented 4 months ago

Dependencies are other reactive variables.

Examples:

import asyncio
import time
import solara
from solara.lab import reactive_task

x = solara.reactive(2)

@reactive_task
async def x_square():
    await asyncio.sleep(2)
    a = b
    return x.value**2

@solara.component
def Page():
    solara.SliderInt("x", value=x, min=0, max=10)
    if x_square.value.state == solara.ResultState.FINISHED:
        solara.Text(repr(x_square.value.value))
    solara.ProgressLinear(x_square.value.state == solara.ResultState.RUNNING)
maartenbreddels commented 4 months ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @maartenbreddels and the rest of your teammates on Graphite Graphite