Skip to content

Commit b6e19d5

Browse files
committed
Add note to docs about always_update
1 parent 5156b3b commit b6e19d5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/guide/reactivity.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ If you click the buttons in the above example it will show the current count. Wh
165165

166166
## Watch methods
167167

168-
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.
168+
Watch methods are another superpower.
169+
Textual will call watch methods when reactive attributes are modified.
170+
Watch methods begin with `watch_` followed by the name of the attribute.
171+
If the watch method accepts a positional argument, it will be called with the new assigned value.
172+
If the watch method accepts *two* positional arguments, it will be called with both the *old* value and the *new* value.
169173

170174
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"`.
171175

@@ -192,6 +196,12 @@ The following app will display any color you type in to the input. Try it with a
192196

193197
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.
194198

199+
!! warning
200+
201+
Textual only calls watch methods if the value of a reactive attribute changes.
202+
If the newly assigned value is the same as the previous value, the watch method is not called.
203+
You can override this behaviour by passing `always_update=True`.
204+
195205
## Compute methods
196206

197207
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.

0 commit comments

Comments
 (0)