Skip to content

Commit e0e3f8d

Browse files
committed
no copy
1 parent 05dad38 commit e0e3f8d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

docs/guide/reactivity.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ Note the call to `mutate_reactive`. Without it, the display would not update whe
410410

411411
## Data binding
412412

413-
Reactive attributes from one widget may be *bound* (connected) to another widget, so that changes to a single reactive will automatically update another widget (potentially more than one).
413+
Reactive attributes may be *bound* (connected) to attributes on child widgets, so that changes to the parent are automatically reflected in the children.
414+
This can simplify working with compound widgets where the value of an attribute might be used in multiple places.
414415

415416
To bind reactive attributes, call [data_bind][textual.dom.DOMNode.data_bind] on a widget.
416417
This method accepts reactives (as class attributes) in positional arguments or keyword arguments.

src/textual/dom.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import re
1010
import threading
11-
from copy import copy
1211
from functools import lru_cache, partial
1312
from inspect import getfile
1413
from typing import (
@@ -280,6 +279,7 @@ def compose(self) -> ComposeResult:
280279
yield WorldClock("Asia/Tokyo").data_bind(WorldClockApp.time)
281280
```
282281
282+
283283
Raises:
284284
ReactiveError: If the data wasn't bound.
285285
@@ -335,10 +335,8 @@ def setter(value: object) -> None:
335335
"""Set bound data."""
336336
_rich_traceback_omit = True
337337
Reactive._initialize_object(self)
338-
# Copy the bound value
339-
# Sharing the same instance with mutable objects can lead to confusing behavior
340-
# Wrap the value in `_Mutated` so the setter knows to invoke watchers etc
341-
setattr(self, variable_name, _Mutated(copy(value)))
338+
# Wrap the value in `_Mutated` so the setter knows to invoke watchers etc.
339+
setattr(self, variable_name, _Mutated(value))
342340

343341
return setter
344342

0 commit comments

Comments
 (0)