Clear separation of model and view concerns in Solara? #88
-
In the docs we see this example: import solara
clicks = solara.reactive(0)
@solara.component
def Page():
def increase_clicks():
clicks.value += 1
solara.Button(label=f"Clicked {clicks} times", on_click=increase_clicks) What bothers me about this is:
PS. I maintain a list of pure python web frameworks. I know that Solara is shooting to be a Class A framework - industrial strength. I hope the devs can address my concerns so it gets there. |
Beta Was this translation helpful? Give feedback.
Answered by
maartenbreddels
May 13, 2023
Replies: 1 comment 6 replies
-
Hi, I appreciate that you are concerned about this since we also find it very important to have state and UI clearly separated.
Maybe the following code resonates better with you, where all logic that modifies the state is outside of the UI component. import solara
class State:
clicks = solara.reactive(0)
@staticmethod
def increase_clicks():
print("lala")
State.clicks.value += 1
@solara.component
def Page():
solara.Button(label=f"Clicked {State.clicks.value} times", on_click=State.increase_clicks) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, I think I understand the confusion.
solara.reactive
has nothing to do with the interface. It's a container around data to make it reactive. This is in solara how we separate UI from application state/data.Also see https://solara.dev/examples/utilities/todo , where we store todo items in a dataclass . I hope that helps.
Does this clarify things?