-
Notifications
You must be signed in to change notification settings - Fork 114
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
Batch update: automatically? #637
Comments
This |
from The Zen of Python: "Explicit is better than implicit." I think if you make this default / automatic in callbacks it might be confusing as users could expect multiple renders from setting multiple reactive values. wrt tasks, I do at the moment set reactives in the global scope from tasks, so that would break my use case but if things become clearer (or glitch-free, no illegal states/incompatible combination of interdependent reactive values) then I wouldn't mind refactoring that |
Current situation
Currently, doing two state changes in a callback, will result in two render passes. If rendering is seen as a side-effect, rendering should only happen after the event handler is finished.
The workaround to get batch updates in event handlers for now is: (not a public solara API, might break in the future):
This has the upside of being explicit and allowing people to opt out (by simply not doing this).
Making this the default in Solara 2.0?
If we make batch updates in event handlers the default behaviour, it would be difficult to opt out (I cannot think of a good name or a way to signal this as a user).
Better API in 2.0?
Instead of making it a default and not easy to use (you have to get a handle to the render-context from the main render loop), we can think of a
solara.batch_update()
function/context-manager that more explicitly conveys intent.Consistency with tasks
If callbacks do automatic batch updating, people might expect a task to do the same. Should we even allow people to update reactive variables from a task, or should we only allow a return value (force them to be pure)? The progress value would then be an exception to this, since that is typically updated in a loop:
The text was updated successfully, but these errors were encountered: