You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/reactivity.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,11 @@ If you click the buttons in the above example it will show the current count. Wh
165
165
166
166
## Watch methods
167
167
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.
169
173
170
174
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"`.
171
175
@@ -192,6 +196,12 @@ The following app will display any color you type in to the input. Try it with a
192
196
193
197
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.
194
198
199
+
### When are watch methods called?
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` to `reactive`.
204
+
195
205
## Compute methods
196
206
197
207
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