robject 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robject-0.1.0/LICENSE +21 -0
- robject-0.1.0/PKG-INFO +164 -0
- robject-0.1.0/README.md +140 -0
- robject-0.1.0/pyproject.toml +36 -0
- robject-0.1.0/setup.cfg +4 -0
- robject-0.1.0/src/robject/__init__.py +37 -0
- robject-0.1.0/src/robject/_core.py +358 -0
- robject-0.1.0/src/robject/_object.py +428 -0
- robject-0.1.0/src/robject/py.typed +0 -0
- robject-0.1.0/src/robject.egg-info/PKG-INFO +164 -0
- robject-0.1.0/src/robject.egg-info/SOURCES.txt +13 -0
- robject-0.1.0/src/robject.egg-info/dependency_links.txt +1 -0
- robject-0.1.0/src/robject.egg-info/top_level.txt +1 -0
- robject-0.1.0/tests/test_readme.py +40 -0
- robject-0.1.0/tests/test_robject.py +491 -0
robject-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nehz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
robject-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: robject
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reactive objects for Python: observable fields, auto-tracked computed properties, effects, subscriptions and batching.
|
|
5
|
+
Author: nehz
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://example.com/robject
|
|
8
|
+
Keywords: reactive,observable,signals,computed,state,observer
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# robject
|
|
26
|
+
|
|
27
|
+
**Reactive objects for Python.** Declare a class the way you would a dataclass,
|
|
28
|
+
and its attributes become observable. Derived values recompute only when what
|
|
29
|
+
they read actually changed, side effects re-run automatically, and a burst of
|
|
30
|
+
writes can be grouped into a single notification.
|
|
31
|
+
|
|
32
|
+
It's the signals / computed / effect model from modern UI frameworks, packaged
|
|
33
|
+
as plain Python classes. Pure standard library, no dependencies.
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from robject import RObject, computed, effect, batch
|
|
37
|
+
|
|
38
|
+
class Cart(RObject):
|
|
39
|
+
price: float = 0.0
|
|
40
|
+
qty: int = 1
|
|
41
|
+
|
|
42
|
+
@computed
|
|
43
|
+
def total(self) -> float:
|
|
44
|
+
return self.price * self.qty
|
|
45
|
+
|
|
46
|
+
cart = Cart(price=2.5)
|
|
47
|
+
effect(lambda: print("total is", cart.total)) # prints: total is 2.5
|
|
48
|
+
|
|
49
|
+
with batch():
|
|
50
|
+
cart.price = 3.0
|
|
51
|
+
cart.qty = 4
|
|
52
|
+
# prints once: total is 12.0
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Reactive fields** from ordinary class annotations, with defaults,
|
|
58
|
+
required fields, `field(default_factory=...)` and inheritance.
|
|
59
|
+
- **`@computed` properties**: lazy, cached and read-only. Dependencies are tracked
|
|
60
|
+
automatically, including dynamic ones (branches) and ones on other objects.
|
|
61
|
+
Exceptions are cached too, and cycles are detected.
|
|
62
|
+
- **Effects** re-run whenever anything they read changes. They are glitch-free:
|
|
63
|
+
an effect never sees a half-updated state.
|
|
64
|
+
- **Subscriptions** deliver `Change(obj, name, old, new)` events for fields and
|
|
65
|
+
computed properties. A computed property notifies only when its value really
|
|
66
|
+
changes.
|
|
67
|
+
- **Batching** coalesces writes. Subscribers get one event per attribute (none
|
|
68
|
+
if the value ends up back where it started), and effects run once.
|
|
69
|
+
- **Safety rails**: an error in one callback doesn't stop the others (the first
|
|
70
|
+
one is re-raised afterwards), and runaway feedback loops raise instead of hanging.
|
|
71
|
+
- Typed (`py.typed`), standard library only, Python 3.10+.
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
From a checkout (the package is not published to PyPI):
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
79
|
+
pip install .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quickstart
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from robject import RObject, Change, batch, computed, effect, field, subscribe
|
|
86
|
+
|
|
87
|
+
class Todo(RObject):
|
|
88
|
+
title: str # required
|
|
89
|
+
done: bool = False
|
|
90
|
+
tags: list = field(default_factory=list) # mutable defaults need a factory
|
|
91
|
+
|
|
92
|
+
class TodoList(RObject):
|
|
93
|
+
items: tuple = ()
|
|
94
|
+
|
|
95
|
+
@computed
|
|
96
|
+
def remaining(self) -> int:
|
|
97
|
+
return sum(not t.done for t in self.items)
|
|
98
|
+
|
|
99
|
+
todos = TodoList(items=(Todo(title="write docs"), Todo(title="ship")))
|
|
100
|
+
|
|
101
|
+
# Subscribe to specific attributes (or all of them, by passing no names).
|
|
102
|
+
unsubscribe = subscribe(todos, lambda ch: print(f"{ch.name}: {ch.old} -> {ch.new}"), "remaining")
|
|
103
|
+
|
|
104
|
+
todos.items[0].done = True # prints: remaining: 2 -> 1
|
|
105
|
+
|
|
106
|
+
# Effects track whatever they read, across objects.
|
|
107
|
+
watcher = effect(lambda: print("left:", todos.remaining)) # prints: left: 1
|
|
108
|
+
|
|
109
|
+
with batch(): # delivery waits until the block ends
|
|
110
|
+
todos.items[1].done = True # remaining: 1 -> 0 ...
|
|
111
|
+
todos.items = todos.items + (Todo(title="celebrate"),) # ... -> 1
|
|
112
|
+
# The effect re-runs once and prints: left: 1
|
|
113
|
+
# `remaining` ended where it started, so the subscriber prints nothing.
|
|
114
|
+
|
|
115
|
+
watcher.dispose()
|
|
116
|
+
unsubscribe()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Fields are tracked by assignment. Mutating a list in place (`todo.tags.append(...)`)
|
|
120
|
+
is invisible, so assign a new value instead (`todo.tags = [*todo.tags, "x"]`), or use
|
|
121
|
+
immutable containers such as tuples.
|
|
122
|
+
|
|
123
|
+
## API overview
|
|
124
|
+
|
|
125
|
+
Everything below is importable from `robject`.
|
|
126
|
+
|
|
127
|
+
| Name | Description |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `RObject` | Base class. Annotated class attributes become reactive fields (except `ClassVar`). Instances are constructed with keyword arguments only. Unknown names and missing required fields raise `TypeError`. A subclass that defines `__init__` must call `super().__init__(**kwargs)`. `repr()` shows the field values. |
|
|
130
|
+
| `field(*, default=..., default_factory=None)` | Explicit field declaration. You need it for mutable defaults: a bare `list`/`dict`/`set`/`bytearray` default raises `ValueError`. |
|
|
131
|
+
| `computed` | Decorator for a lazy, cached, read-only property whose dependencies are tracked. Assigning to it raises `AttributeError`. Exceptions are cached until a dependency changes, and self-reference raises `RuntimeError("cycle detected ...")`. |
|
|
132
|
+
| `effect(fn) -> Effect` | Runs `fn()` now and again after any reactive value it read changes. If the first run raises, the effect is disposed and the exception propagates. Also works as a decorator. |
|
|
133
|
+
| `Effect` | Returned by `effect`. Has `.dispose()`, `.run()`, a `.runs` counter and `.disposed`. It is also a context manager that disposes on exit. |
|
|
134
|
+
| `subscribe(obj, callback, *names) -> unsubscribe` | Calls `callback(Change)` when the named fields or computed properties of `obj` change. With no names it watches all of them. Unknown names raise `ValueError`. Watched computed properties are re-evaluated eagerly. The returned function cancels the subscription and is idempotent. |
|
|
135
|
+
| `Change` | `NamedTuple(obj, name, old, new)`. For a computed property whose previous evaluation raised, `old` is `None`. |
|
|
136
|
+
| `batch()` | Context manager (and decorator) that defers delivery until the outermost batch exits, including on exception. Reads inside a batch already see the new values. |
|
|
137
|
+
| `untracked()` | Context manager. Reads inside it don't become dependencies. |
|
|
138
|
+
| `fields(obj_or_cls) -> tuple[str, ...]` | Field names in declaration order, with base classes first. |
|
|
139
|
+
| `snapshot(obj, *, include_computed=False) -> dict` | Plain `dict` of the current values. Reading it inside an effect makes the effect depend on every included attribute. |
|
|
140
|
+
| `__version__` | `"0.1.0"` |
|
|
141
|
+
|
|
142
|
+
### Semantics worth knowing
|
|
143
|
+
|
|
144
|
+
- A write that is `==` to the current value is a no-op.
|
|
145
|
+
- Outside a batch, delivery is synchronous: by the time an assignment returns,
|
|
146
|
+
subscribers and effects have run.
|
|
147
|
+
- Subscribers and effects may write to reactive values. Their work is processed
|
|
148
|
+
in further rounds of the same flush. If 100 rounds pass without settling, the
|
|
149
|
+
flush raises `RuntimeError("reactive updates did not settle ...")`.
|
|
150
|
+
- An effect's own reads are tracked; reads made by callbacks it triggers are not.
|
|
151
|
+
- The reactive graph is process-global and **not thread-safe**. Use it from one
|
|
152
|
+
thread, such as a UI or event-loop thread.
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
python3 -m unittest discover -s tests -v
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The tests use only `unittest`, so `python3 -m pytest` works too if you have pytest.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|
robject-0.1.0/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# robject
|
|
2
|
+
|
|
3
|
+
**Reactive objects for Python.** Declare a class the way you would a dataclass,
|
|
4
|
+
and its attributes become observable. Derived values recompute only when what
|
|
5
|
+
they read actually changed, side effects re-run automatically, and a burst of
|
|
6
|
+
writes can be grouped into a single notification.
|
|
7
|
+
|
|
8
|
+
It's the signals / computed / effect model from modern UI frameworks, packaged
|
|
9
|
+
as plain Python classes. Pure standard library, no dependencies.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from robject import RObject, computed, effect, batch
|
|
13
|
+
|
|
14
|
+
class Cart(RObject):
|
|
15
|
+
price: float = 0.0
|
|
16
|
+
qty: int = 1
|
|
17
|
+
|
|
18
|
+
@computed
|
|
19
|
+
def total(self) -> float:
|
|
20
|
+
return self.price * self.qty
|
|
21
|
+
|
|
22
|
+
cart = Cart(price=2.5)
|
|
23
|
+
effect(lambda: print("total is", cart.total)) # prints: total is 2.5
|
|
24
|
+
|
|
25
|
+
with batch():
|
|
26
|
+
cart.price = 3.0
|
|
27
|
+
cart.qty = 4
|
|
28
|
+
# prints once: total is 12.0
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Reactive fields** from ordinary class annotations, with defaults,
|
|
34
|
+
required fields, `field(default_factory=...)` and inheritance.
|
|
35
|
+
- **`@computed` properties**: lazy, cached and read-only. Dependencies are tracked
|
|
36
|
+
automatically, including dynamic ones (branches) and ones on other objects.
|
|
37
|
+
Exceptions are cached too, and cycles are detected.
|
|
38
|
+
- **Effects** re-run whenever anything they read changes. They are glitch-free:
|
|
39
|
+
an effect never sees a half-updated state.
|
|
40
|
+
- **Subscriptions** deliver `Change(obj, name, old, new)` events for fields and
|
|
41
|
+
computed properties. A computed property notifies only when its value really
|
|
42
|
+
changes.
|
|
43
|
+
- **Batching** coalesces writes. Subscribers get one event per attribute (none
|
|
44
|
+
if the value ends up back where it started), and effects run once.
|
|
45
|
+
- **Safety rails**: an error in one callback doesn't stop the others (the first
|
|
46
|
+
one is re-raised afterwards), and runaway feedback loops raise instead of hanging.
|
|
47
|
+
- Typed (`py.typed`), standard library only, Python 3.10+.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
From a checkout (the package is not published to PyPI):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
55
|
+
pip install .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from robject import RObject, Change, batch, computed, effect, field, subscribe
|
|
62
|
+
|
|
63
|
+
class Todo(RObject):
|
|
64
|
+
title: str # required
|
|
65
|
+
done: bool = False
|
|
66
|
+
tags: list = field(default_factory=list) # mutable defaults need a factory
|
|
67
|
+
|
|
68
|
+
class TodoList(RObject):
|
|
69
|
+
items: tuple = ()
|
|
70
|
+
|
|
71
|
+
@computed
|
|
72
|
+
def remaining(self) -> int:
|
|
73
|
+
return sum(not t.done for t in self.items)
|
|
74
|
+
|
|
75
|
+
todos = TodoList(items=(Todo(title="write docs"), Todo(title="ship")))
|
|
76
|
+
|
|
77
|
+
# Subscribe to specific attributes (or all of them, by passing no names).
|
|
78
|
+
unsubscribe = subscribe(todos, lambda ch: print(f"{ch.name}: {ch.old} -> {ch.new}"), "remaining")
|
|
79
|
+
|
|
80
|
+
todos.items[0].done = True # prints: remaining: 2 -> 1
|
|
81
|
+
|
|
82
|
+
# Effects track whatever they read, across objects.
|
|
83
|
+
watcher = effect(lambda: print("left:", todos.remaining)) # prints: left: 1
|
|
84
|
+
|
|
85
|
+
with batch(): # delivery waits until the block ends
|
|
86
|
+
todos.items[1].done = True # remaining: 1 -> 0 ...
|
|
87
|
+
todos.items = todos.items + (Todo(title="celebrate"),) # ... -> 1
|
|
88
|
+
# The effect re-runs once and prints: left: 1
|
|
89
|
+
# `remaining` ended where it started, so the subscriber prints nothing.
|
|
90
|
+
|
|
91
|
+
watcher.dispose()
|
|
92
|
+
unsubscribe()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Fields are tracked by assignment. Mutating a list in place (`todo.tags.append(...)`)
|
|
96
|
+
is invisible, so assign a new value instead (`todo.tags = [*todo.tags, "x"]`), or use
|
|
97
|
+
immutable containers such as tuples.
|
|
98
|
+
|
|
99
|
+
## API overview
|
|
100
|
+
|
|
101
|
+
Everything below is importable from `robject`.
|
|
102
|
+
|
|
103
|
+
| Name | Description |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `RObject` | Base class. Annotated class attributes become reactive fields (except `ClassVar`). Instances are constructed with keyword arguments only. Unknown names and missing required fields raise `TypeError`. A subclass that defines `__init__` must call `super().__init__(**kwargs)`. `repr()` shows the field values. |
|
|
106
|
+
| `field(*, default=..., default_factory=None)` | Explicit field declaration. You need it for mutable defaults: a bare `list`/`dict`/`set`/`bytearray` default raises `ValueError`. |
|
|
107
|
+
| `computed` | Decorator for a lazy, cached, read-only property whose dependencies are tracked. Assigning to it raises `AttributeError`. Exceptions are cached until a dependency changes, and self-reference raises `RuntimeError("cycle detected ...")`. |
|
|
108
|
+
| `effect(fn) -> Effect` | Runs `fn()` now and again after any reactive value it read changes. If the first run raises, the effect is disposed and the exception propagates. Also works as a decorator. |
|
|
109
|
+
| `Effect` | Returned by `effect`. Has `.dispose()`, `.run()`, a `.runs` counter and `.disposed`. It is also a context manager that disposes on exit. |
|
|
110
|
+
| `subscribe(obj, callback, *names) -> unsubscribe` | Calls `callback(Change)` when the named fields or computed properties of `obj` change. With no names it watches all of them. Unknown names raise `ValueError`. Watched computed properties are re-evaluated eagerly. The returned function cancels the subscription and is idempotent. |
|
|
111
|
+
| `Change` | `NamedTuple(obj, name, old, new)`. For a computed property whose previous evaluation raised, `old` is `None`. |
|
|
112
|
+
| `batch()` | Context manager (and decorator) that defers delivery until the outermost batch exits, including on exception. Reads inside a batch already see the new values. |
|
|
113
|
+
| `untracked()` | Context manager. Reads inside it don't become dependencies. |
|
|
114
|
+
| `fields(obj_or_cls) -> tuple[str, ...]` | Field names in declaration order, with base classes first. |
|
|
115
|
+
| `snapshot(obj, *, include_computed=False) -> dict` | Plain `dict` of the current values. Reading it inside an effect makes the effect depend on every included attribute. |
|
|
116
|
+
| `__version__` | `"0.1.0"` |
|
|
117
|
+
|
|
118
|
+
### Semantics worth knowing
|
|
119
|
+
|
|
120
|
+
- A write that is `==` to the current value is a no-op.
|
|
121
|
+
- Outside a batch, delivery is synchronous: by the time an assignment returns,
|
|
122
|
+
subscribers and effects have run.
|
|
123
|
+
- Subscribers and effects may write to reactive values. Their work is processed
|
|
124
|
+
in further rounds of the same flush. If 100 rounds pass without settling, the
|
|
125
|
+
flush raises `RuntimeError("reactive updates did not settle ...")`.
|
|
126
|
+
- An effect's own reads are tracked; reads made by callbacks it triggers are not.
|
|
127
|
+
- The reactive graph is process-global and **not thread-safe**. Use it from one
|
|
128
|
+
thread, such as a UI or event-loop thread.
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
python3 -m unittest discover -s tests -v
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The tests use only `unittest`, so `python3 -m pytest` works too if you have pytest.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "robject"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Reactive objects for Python: observable fields, auto-tracked computed properties, effects, subscriptions and batching."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "nehz" }]
|
|
13
|
+
keywords = ["reactive", "observable", "signals", "computed", "state", "observer"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dependencies = []
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://example.com/robject"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
robject = ["py.typed"]
|
robject-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""robject: reactive objects for Python.
|
|
2
|
+
|
|
3
|
+
Declare plain classes whose attributes are observable, derive cached
|
|
4
|
+
``computed`` properties that track their own dependencies, react to changes
|
|
5
|
+
with ``effect`` and ``subscribe``, and group writes with ``batch``.
|
|
6
|
+
|
|
7
|
+
>>> from robject import RObject, computed
|
|
8
|
+
>>> class Cart(RObject):
|
|
9
|
+
... price: float = 0.0
|
|
10
|
+
... qty: int = 1
|
|
11
|
+
... @computed
|
|
12
|
+
... def total(self) -> float:
|
|
13
|
+
... return self.price * self.qty
|
|
14
|
+
>>> cart = Cart(price=2.5, qty=4)
|
|
15
|
+
>>> cart.total
|
|
16
|
+
10.0
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from ._core import Effect, batch, effect, untracked
|
|
20
|
+
from ._object import Change, RObject, computed, field, fields, snapshot, subscribe
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"RObject",
|
|
26
|
+
"field",
|
|
27
|
+
"computed",
|
|
28
|
+
"effect",
|
|
29
|
+
"Effect",
|
|
30
|
+
"batch",
|
|
31
|
+
"untracked",
|
|
32
|
+
"subscribe",
|
|
33
|
+
"Change",
|
|
34
|
+
"fields",
|
|
35
|
+
"snapshot",
|
|
36
|
+
"__version__",
|
|
37
|
+
]
|