python-library-reactive-model 0.1.0__tar.gz → 0.1.2__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.
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-library-reactive-model
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Requires-Python: >=3.10
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "python-library-reactive-model"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  requires-python = ">=3.10"
9
9
  dependencies = []
10
10
 
@@ -10,12 +10,23 @@ _MISSING = object()
10
10
 
11
11
 
12
12
  class ComputedModel(ReactiveModel[T]):
13
- def __init__(self, expr: Callable[[], T]) -> None:
13
+ def __init__(self, expr: Callable[[], T]=None) -> None:
14
+ """
15
+ Args:
16
+ expr: The expression to compute the value.
17
+ """
14
18
  super().__init__()
15
19
  self._expr = expr
16
20
  self._cache: T | object = _MISSING
17
21
  self._deps: dict[int, tuple[Trackable, int]] = {}
18
22
 
23
+ def compute(self, expr: Callable[[], T]) -> None:
24
+ """
25
+ Args:
26
+ expr: The expression to compute the value.
27
+ """
28
+ self._expr = expr
29
+
19
30
  @property
20
31
  def value(self) -> T:
21
32
  if self._needs_recompute():
@@ -40,6 +51,9 @@ class ComputedModel(ReactiveModel[T]):
40
51
  return False
41
52
 
42
53
  def _recompute(self) -> None:
54
+ if self._expr is None:
55
+ raise ValueError("require expr to compute")
56
+
43
57
  collector = Collector()
44
58
 
45
59
  with compute_context(self, collector):