-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1145 from Textualize/instant-watchers
make watchers instant
- Loading branch information
Showing
3 changed files
with
93 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.reactive import reactive | ||
|
||
|
||
class WatchApp(App): | ||
|
||
count = reactive(0, init=False) | ||
|
||
test_count = 0 | ||
|
||
def watch_count(self, value: int) -> None: | ||
self.test_count = value | ||
|
||
|
||
async def test_watch(): | ||
"""Test that changes to a watched reactive attribute happen immediately.""" | ||
app = WatchApp() | ||
async with app.run_test(): | ||
app.count += 1 | ||
assert app.test_count == 1 | ||
app.count += 1 | ||
assert app.test_count == 2 | ||
app.count -= 1 | ||
assert app.test_count == 1 | ||
app.count -= 1 | ||
assert app.test_count == 0 |