Add note to docs about always_update

This commit is contained in:
Darren Burns
2022-10-25 14:39:39 +01:00
parent 5156b3bc70
commit b6e19d5c30

View File

@@ -165,7 +165,11 @@ If you click the buttons in the above example it will show the current count. Wh
## Watch methods
Watch methods are another superpower. Textual will call watch methods when reactive attributes are modified. Watch methods begin with `watch_` followed by the name of the attribute. If the watch method accepts a positional argument, it will be called with the new assigned value. If the watch method accepts *two* positional arguments, it will be called with both the *old* value and the *new* value.
Watch methods are another superpower.
Textual will call watch methods when reactive attributes are modified.
Watch methods begin with `watch_` followed by the name of the attribute.
If the watch method accepts a positional argument, it will be called with the new assigned value.
If the watch method accepts *two* positional arguments, it will be called with both the *old* value and the *new* value.
The following app will display any color you type in to the input. Try it with a valid color in Textual CSS. For example `"darkorchid"` or `"#52de44"`.
@@ -192,6 +196,12 @@ The following app will display any color you type in to the input. Try it with a
The color is parsed in `on_input_submitted` and assigned to `self.color`. Because `color` is reactive, Textual also calls `watch_color` with the old and new values.
!! warning
Textual only calls watch methods if the value of a reactive attribute changes.
If the newly assigned value is the same as the previous value, the watch method is not called.
You can override this behaviour by passing `always_update=True`.
## Compute methods
Compute methods are the final superpower offered by the `reactive` descriptor. Textual runs compute methods to calculate the value of a reactive attribute. Compute methods begin with `compute_` followed by the name of the reactive value.