Skip to content
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

feat: computed reactive variables #455

Merged

Conversation

maartenbreddels
Copy link
Contributor

@maartenbreddels maartenbreddels commented Jan 10, 2024

Creates a reactive variable that is set to the return value of the function.

The value will be updated when any of the reactive variables used in the function
change.

Example:

import solara
import solara.lab


a = solara.reactive(1)
b = solara.reactive(2)

@solara.lab.computed
def total():
    return a.value + b.value

def reset():
    a.value = 1
    b.value = 2

@solara.component
def Page():
    print(a, b, total)
    solara.IntSlider("a", value=a)
    solara.IntSlider("b", value=b)
    solara.Text(f"a + b = {total.value}")
    solara.Button("reset", on_click=reset)

z.value will be lazily executed the first time, and will be updated
when one of the dependencies changes.

Copy link
Contributor Author

maartenbreddels commented Jan 10, 2024

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

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

@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from eca69f7 to 530c72b Compare January 12, 2024 11:13
@maartenbreddels maartenbreddels force-pushed the 01-10-refactor_make_a_base_class_for_reactive_auto_subscribe_context_manager branch from 58fe1a8 to 1e3ab7e Compare January 12, 2024 13:02
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch 2 times, most recently from 2a2db1c to f4e000c Compare January 18, 2024 09:33
@maartenbreddels maartenbreddels changed the base branch from 01-10-refactor_make_a_base_class_for_reactive_auto_subscribe_context_manager to master January 18, 2024 09:33
@maartenbreddels maartenbreddels changed the base branch from master to 01-18-feat_on_kernel_start_triggers_callback_on_virtual_kernel_start January 19, 2024 10:47
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from f4e000c to fd38bdc Compare January 19, 2024 10:47
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from fd38bdc to d729d5d Compare January 19, 2024 12:58
@maartenbreddels maartenbreddels force-pushed the 01-18-feat_on_kernel_start_triggers_callback_on_virtual_kernel_start branch from 6e163fd to 0933395 Compare January 19, 2024 19:37
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch 2 times, most recently from 96720b1 to fd6ce25 Compare January 19, 2024 20:36
@maartenbreddels maartenbreddels changed the title feat: Computed reactive variables and Singleton. feat: computed reactive variables Jan 19, 2024
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch 2 times, most recently from 3e25f02 to c2c3c95 Compare January 22, 2024 11:48
@iisakkirotko iisakkirotko force-pushed the 01-18-feat_on_kernel_start_triggers_callback_on_virtual_kernel_start branch from 0933395 to a99f167 Compare February 5, 2024 13:36
@iisakkirotko iisakkirotko force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from c2c3c95 to 0134661 Compare February 5, 2024 13:36
@iisakkirotko iisakkirotko force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from 0134661 to a2b582f Compare February 5, 2024 14:56
@maartenbreddels maartenbreddels marked this pull request as ready for review February 8, 2024 11:06
@iisakkirotko iisakkirotko force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from a2b582f to 6acaeba Compare February 8, 2024 16:04
@iisakkirotko iisakkirotko force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from 6acaeba to 5b55459 Compare February 8, 2024 16:14
@iisakkirotko iisakkirotko changed the base branch from 01-18-feat_on_kernel_start_triggers_callback_on_virtual_kernel_start to master February 8, 2024 16:14
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch 2 times, most recently from bbb7584 to 7bd5707 Compare February 9, 2024 15:22
* feat: get_kernel_id and get_session_id for custom storage

If you want to store data in a custom storage, you need to know the
kernel_id or session_id to scope.

This can be used to implement something similar to reactive variables.
Creates a reactive variable that is set to the return value of the function.

The value will be updated when any of the reactive variables used in the function
change.

Example:
```solara
import solara
import solara.lab

a = solara.reactive(1)
b = solara.reactive(2)

@solara.lab.computed
def total():
    return a.value + b.value

def reset():
    a.value = 1
    b.value = 2

@solara.component
def Page():
    print(a, b, total)
    solara.IntSlider("a", value=a)
    solara.IntSlider("b", value=b)
    solara.Text(f"a + b = {total.value}")
    solara.Button("reset", on_click=reset)
```

z.value will be lazily executed the first time, and will be updated
when one of the dependencies changes.
@maartenbreddels maartenbreddels force-pushed the 01-10-feat_Computed_reactive_variables_and_Singleton branch from 7bd5707 to 7d63ad0 Compare February 9, 2024 16:10
@maartenbreddels maartenbreddels merged commit 92df9f0 into master Feb 9, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant