make watchers instant

This commit is contained in:
Will McGugan
2022-11-09 12:06:14 +00:00
parent 3594cf9277
commit dd5c0e612a
2 changed files with 68 additions and 33 deletions

26
tests/test_reactive.py Normal file
View File

@@ -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