-
Notifications
You must be signed in to change notification settings - Fork 733
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
compute_*
methods don't run unless the changed reactive
has a watch_*
method
#1274
Comments
I just tested Textual v0.5.0 and realized there's another issue with the textual/src/textual/reactive.py Lines 256 to 260 in 9fd0149
|
Further investigation required for this, but 395616f could be relevant; with that commit reverted, the Note: I haven't yet checked whether that affects the linked issues. |
@willmcgugan would you mind clarifying the intended behavior? I'd be happy to put up a PR to get things into the desired state (changing either the docs or the code as needed). I imagine 395616f was intended to optimize Either way, I think I'll need to swap the |
We're tracking the issue here #1227 But we may go with some changes to the behaviour. Compute methods should be called regardless if there is a corresponding watch method. Compute methods look like properties, but weren't intended to be so. The idea was that you could watch computed properties and get notified when something changes. In retrospect, perhaps they should additionally be called on demand. So they behave more like properties. |
Gotcha, I'll follow along on #1227 ! Thanks for the update. |
I'm closing this as the original code already works without having to add a dummy |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
It looks like
compute_*
methods aren't called unless there's awatch_*
method for the attribute that is actually changing, i.e., this statement in the docs from https://textual.textualize.io/guide/reactivity/#compute-methods is wrong:I noticed this in my own app but you can see it in the
computed01.py
example in the docs linked above. If you try it as-is, the background will never update becausecompute_color
is never called. Adding awatch_*
method for one of the three colors makes it update when that color is changed.For example, make this modification:
Then the background will actually update, but only when the blue input changes.
I suspect the problem is in this chunk of logic which decides when to run computes, where it seems like the decision is only based on whether any watchers are running synchronously, not on whether the reactive attribute value changed:
textual/src/textual/reactive.py
Lines 248 to 266 in 9fd0149
Potentially related to some issues @darrenburns filed recently around compute methods: #1218 #1227
The text was updated successfully, but these errors were encountered: