Replies: 1 comment
-
I ran into |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been exploring the capabilities of NiceGUI and recently stumbled upon an interesting challenge regarding global and local states.
Global vs Local State Management
One of the things I appreciated from architectural patterns like MVC and MVU is the ability to distinguish between global and local updates. For instance:
This distinction is incredibly useful when building dynamic and interactive web applications, and I wanted to discuss how we can achieve this in NiceGUI.
A Practical Example
Here’s a simplified example to illustrate how global and local states might be managed in NiceGUI:
Discussion Points
Global State Handling:
In the example above, the GlobalState class is designed to maintain a shared counter. However, broadcasting changes to all connected clients isn’t straightforward. Is there an idiomatic way to broadcast updates in NiceGUI using the app.clients API? Would security be an issue here?
Local State Handling:
The LocalState class encapsulates client-specific data. How can we tie this more directly to the session or client instance in NiceGUI?
Are there best practices for binding local states to UI components dynamically when users connect?
Closing Thoughts
Given how NiceGUI's auto-index client can determine if events are global (or not) already, are there any ways that I can leverage that in choosing in some sense what does get globally updated and what doesn't?
For example, in the code that I provided, everything would technically be global state. If I were to wrap it inside a ui.page, the content inside there would be local.
I realize that for an example like this, it wouldn't be too hard to work out a hacky solution, but I'm interested to see if we can expand this into a more general solution, or if that's even possible.
Looking forward to your thoughts and advice!
Beta Was this translation helpful? Give feedback.
All reactions