Skip to content

Commit 1080a5b

Browse files
committed
Fork declare
1 parent 6f7e313 commit 1080a5b

File tree

8 files changed

+309
-305
lines changed

8 files changed

+309
-305
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Test
22

33
on:
44
push:
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [ubuntu-latest, macos-latest, windows-latest]
23-
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
23+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
2424

2525
steps:
2626
- name: Checkout
@@ -33,10 +33,15 @@ jobs:
3333
- name: Upgrade pip
3434
run: python3 -m pip install --upgrade pip
3535

36-
- name: Install ypywidgets in dev mode
36+
- name: Install reacttrs in dev mode
3737
run: |
3838
pip install .[test]
3939
40+
- name: Check types
41+
run: |
42+
mypy ./reacttrs
43+
mypy ./tests
44+
4045
- name: Run tests
4146
run: |
42-
pytest ./tests -v
47+
pytest ./tests -v --color=yes

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
# reacttrs
22

3-
Reactive attributes extracted out from [Textual](https://textual.textualize.io/guide/reactivity).
3+
Reactive attributes, initially extracted out from [Textual](https://textual.textualize.io/guide/reactivity), now a fork of [Declare](https://github.com/willmcgugan/declare).
44

55
```py
6-
from reacttrs import reactive
6+
from reacttrs import Int, Str
77

88

99
class Foo:
1010

11-
name = reactive("Paul")
12-
age = reactive(33)
13-
birth = reactive(1990)
11+
name = Str("Paul")
12+
age = Int(34)
13+
birth = Int(1990)
1414

15-
def watch_name(self, old, new):
15+
@name.watch
16+
def _watch_name(self, old: str, new: str):
1617
print(f"{old=}, {new=}")
1718

18-
def validate_name(self, name):
19-
if name == "John":
20-
print("Hey John!")
21-
return name
22-
23-
def compute_age(self) -> int:
24-
age = 2023 - self.birth
25-
print(f"{age=}")
26-
return age
19+
@age.validate
20+
def _validate_age(self, value: int) -> int:
21+
return 2024 - self.birth
2722

2823
foo = Foo()
29-
foo.name = "John"
30-
foo.name = "Steve"
24+
foo.name = "John" # old='Paul', new='John'
25+
foo.name = "Steve" # old='John', new='Steve'
3126

32-
foo.age
27+
print(foo.age) # 34
3328
foo.birth = 1991
34-
foo.age
29+
foo.age = 34
30+
print(foo.age) # 33
3531
```

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ license = "MIT"
1111
requires-python = ">=3.8"
1212
authors = [
1313
{ name = "David Brochart", email = "[email protected]" },
14-
]
15-
keywords = [
16-
"textual",
14+
{ name = "Will McGugan", email = "[email protected]" },
1715
]
1816

1917
[project.urls]
2018
Homepage = "https://github.com/davidbrochart/reacttrs"
2119

2220
[project.optional-dependencies]
2321
test = [
24-
"pytest",
22+
"pytest >=8.1.1",
23+
"mypy >=1.9.0",
2524
]
2625

2726
[tool.hatch.version]

reacttrs/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
from .reactive import reactive # noqa
1+
from __future__ import annotations
2+
3+
from .reactive import Reactive as Reactive
4+
from .reactive import watch as watch
25

36
__version__ = "0.1.4"
7+
8+
__all__ = [
9+
"Reactive",
10+
"Int",
11+
"Float",
12+
"Bool",
13+
"Str",
14+
"Bytes",
15+
"watch",
16+
]
17+
18+
Int: type[Reactive[int]] = Reactive
19+
Float: type[Reactive[float]] = Reactive
20+
Bool: type[Reactive[bool]] = Reactive
21+
Str: type[Reactive[str]] = Reactive
22+
Bytes: type[Reactive[bytes]] = Reactive

reacttrs/_callback.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

reacttrs/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)