hmr 0.0.3__py3-none-any.whl → 0.0.3.1__py3-none-any.whl
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.
- {hmr-0.0.3.dist-info → hmr-0.0.3.1.dist-info}/METADATA +1 -1
- hmr-0.0.3.1.dist-info/RECORD +9 -0
- reactivity/__init__.py +2 -2
- reactivity/functional.py +5 -5
- reactivity/helpers.py +34 -21
- reactivity/hmr.py +6 -3
- reactivity/primitives.py +11 -4
- hmr-0.0.3.dist-info/RECORD +0 -9
- {hmr-0.0.3.dist-info → hmr-0.0.3.1.dist-info}/WHEEL +0 -0
- {hmr-0.0.3.dist-info → hmr-0.0.3.1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
hmr-0.0.3.1.dist-info/METADATA,sha256=lb041EpepaHAh0yvImQPiVofZkBEEnNJ4gQYy2Sv-d0,230
|
2
|
+
hmr-0.0.3.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
+
hmr-0.0.3.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
|
4
|
+
reactivity/__init__.py,sha256=pX-RUzkezCC1x4eOWGxNhXbwrbvBLP_3pQuZr9eZz1Y,300
|
5
|
+
reactivity/functional.py,sha256=U06vshcVhZ0sb218gcmHtEhfgTNAGtQ7zyvPz2w5qKM,1292
|
6
|
+
reactivity/helpers.py,sha256=OogpUAsVnXX60Ib3ckcVWrJX9jwYfYAKFwUEJw3UcsM,3800
|
7
|
+
reactivity/hmr.py,sha256=kBwaVLFCHRz0CX_f5AgTc0Yq8Avknjjnv0LkzGLu4UM,8576
|
8
|
+
reactivity/primitives.py,sha256=lw4G3GpANRGK5dKw11eYc2-nlOJ1uCO3f3MiLa41jG8,3588
|
9
|
+
hmr-0.0.3.1.dist-info/RECORD,,
|
reactivity/__init__.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from .functional import batch, create_effect, create_memo, create_signal, memoized_method, memoized_property
|
2
2
|
from .helpers import Reactive
|
3
|
-
from .primitives import
|
3
|
+
from .primitives import State
|
4
4
|
|
5
|
-
__all__ = ["
|
5
|
+
__all__ = ["Reactive", "State", "batch", "create_effect", "create_memo", "create_signal", "memoized_method", "memoized_property"]
|
reactivity/functional.py
CHANGED
@@ -3,7 +3,7 @@ from functools import wraps
|
|
3
3
|
from typing import Protocol, overload
|
4
4
|
|
5
5
|
from .helpers import Memoized, MemoizedMethod, MemoizedProperty
|
6
|
-
from .primitives import Batch,
|
6
|
+
from .primitives import Batch, Effect, Signal
|
7
7
|
|
8
8
|
|
9
9
|
class Getter[T](Protocol):
|
@@ -19,19 +19,19 @@ def create_signal[T](initial_value: T = None, check_equality=True) -> tuple[Gett
|
|
19
19
|
return signal.get, signal.set
|
20
20
|
|
21
21
|
|
22
|
-
def create_effect[T](fn: Callable[[], T],
|
23
|
-
return
|
22
|
+
def create_effect[T](fn: Callable[[], T], call_immediately=True):
|
23
|
+
return Effect(fn, call_immediately)
|
24
24
|
|
25
25
|
|
26
26
|
def create_memo[T](fn: Callable[[], T]):
|
27
27
|
return Memoized(fn)
|
28
28
|
|
29
29
|
|
30
|
-
def memoized_property[T,
|
30
|
+
def memoized_property[T, I](method: Callable[[I], T]):
|
31
31
|
return MemoizedProperty(method)
|
32
32
|
|
33
33
|
|
34
|
-
def memoized_method[T,
|
34
|
+
def memoized_method[T, I](method: Callable[[I], T]):
|
35
35
|
return MemoizedMethod(method)
|
36
36
|
|
37
37
|
|
reactivity/helpers.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
from collections import defaultdict
|
1
2
|
from collections.abc import Callable, Mapping, MutableMapping
|
2
3
|
from functools import partial
|
4
|
+
from typing import Self, overload
|
3
5
|
from weakref import WeakKeyDictionary
|
4
6
|
|
5
7
|
from .primitives import BaseComputation, Batch, Signal, Subscribable
|
@@ -36,31 +38,44 @@ class Memoized[T](Subscribable, BaseComputation[T]):
|
|
36
38
|
self.is_stale = True
|
37
39
|
|
38
40
|
|
39
|
-
class MemoizedProperty[T,
|
40
|
-
def __init__(self, method: Callable[[
|
41
|
+
class MemoizedProperty[T, I]:
|
42
|
+
def __init__(self, method: Callable[[I], T]):
|
41
43
|
super().__init__()
|
42
44
|
self.method = method
|
43
|
-
self.map = WeakKeyDictionary[
|
45
|
+
self.map = WeakKeyDictionary[I, Memoized[T]]()
|
44
46
|
|
45
|
-
|
47
|
+
@overload
|
48
|
+
def __get__(self, instance: None, owner: type[I]) -> Self: ...
|
49
|
+
@overload
|
50
|
+
def __get__(self, instance: I, owner: type[I]) -> T: ...
|
51
|
+
|
52
|
+
def __get__(self, instance: I | None, owner):
|
53
|
+
if instance is None:
|
54
|
+
return self
|
46
55
|
if func := self.map.get(instance):
|
47
56
|
return func()
|
48
57
|
self.map[instance] = func = Memoized(partial(self.method, instance))
|
49
58
|
return func()
|
50
59
|
|
51
60
|
|
52
|
-
class MemoizedMethod[T,
|
53
|
-
def __init__(self, method: Callable[[
|
61
|
+
class MemoizedMethod[T, I]:
|
62
|
+
def __init__(self, method: Callable[[I], T]):
|
54
63
|
super().__init__()
|
55
64
|
self.method = method
|
56
|
-
self.map = WeakKeyDictionary[
|
65
|
+
self.map = WeakKeyDictionary[I, Memoized[T]]()
|
66
|
+
|
67
|
+
@overload
|
68
|
+
def __get__(self, instance: None, owner: type[I]) -> Self: ...
|
69
|
+
@overload
|
70
|
+
def __get__(self, instance: I, owner: type[I]) -> Memoized[T]: ...
|
57
71
|
|
58
|
-
def __get__(self, instance, owner):
|
59
|
-
|
60
|
-
return self
|
61
|
-
|
62
|
-
self.map[instance] = memo = Memoized(partial(self.method, instance))
|
72
|
+
def __get__(self, instance: I | None, owner):
|
73
|
+
if instance is None:
|
74
|
+
return self
|
75
|
+
if memo := self.map.get(instance):
|
63
76
|
return memo
|
77
|
+
self.map[instance] = memo = Memoized(partial(self.method, instance))
|
78
|
+
return memo
|
64
79
|
|
65
80
|
|
66
81
|
class Reactive[K, V](Subscribable, MutableMapping[K, V]):
|
@@ -69,24 +84,23 @@ class Reactive[K, V](Subscribable, MutableMapping[K, V]):
|
|
69
84
|
def __hash__(self):
|
70
85
|
return id(self)
|
71
86
|
|
72
|
-
def
|
87
|
+
def _null(self):
|
88
|
+
return Signal(self.UNSET, self._check_equality)
|
89
|
+
|
90
|
+
def __init__(self, initial: Mapping[K, V] | None = None, check_equality=True):
|
73
91
|
super().__init__()
|
74
|
-
self._signals
|
92
|
+
self._signals = defaultdict[K, Signal[V]](self._null) if initial is None else defaultdict(self._null, {k: Signal(v, check_equality) for k, v in initial.items()})
|
75
93
|
self._check_equality = check_equality
|
76
94
|
|
77
95
|
def __getitem__(self, key: K):
|
78
|
-
value = self._signals
|
96
|
+
value = self._signals[key].get()
|
79
97
|
if value is self.UNSET:
|
80
98
|
raise KeyError(key)
|
81
99
|
return value
|
82
100
|
|
83
101
|
def __setitem__(self, key: K, value: V):
|
84
102
|
with Batch():
|
85
|
-
|
86
|
-
self._signals[key].set(value)
|
87
|
-
except KeyError:
|
88
|
-
self._signals[key] = Signal(value, self._check_equality)
|
89
|
-
self._signals[key].set(value)
|
103
|
+
self._signals[key].set(value)
|
90
104
|
self.notify()
|
91
105
|
|
92
106
|
def __delitem__(self, key: K):
|
@@ -95,7 +109,6 @@ class Reactive[K, V](Subscribable, MutableMapping[K, V]):
|
|
95
109
|
raise KeyError(key)
|
96
110
|
with Batch():
|
97
111
|
state.set(self.UNSET)
|
98
|
-
state.notify()
|
99
112
|
self.notify()
|
100
113
|
|
101
114
|
def __iter__(self):
|
reactivity/hmr.py
CHANGED
@@ -58,11 +58,14 @@ class ReactiveModule(ModuleType):
|
|
58
58
|
return self.__file
|
59
59
|
raise AttributeError("file")
|
60
60
|
|
61
|
+
def __load(self):
|
62
|
+
code = compile(self.__file.read_text("utf-8"), str(self.__file), "exec", dont_inherit=True)
|
63
|
+
exec(code, self.__namespace, self.__namespace_proxy)
|
64
|
+
|
61
65
|
@property
|
62
66
|
def load(self):
|
63
67
|
if is_called_in_this_file():
|
64
|
-
|
65
|
-
return lambda: exec(code, self.__namespace, self.__namespace_proxy)
|
68
|
+
return self.__load
|
66
69
|
raise AttributeError("load")
|
67
70
|
|
68
71
|
def __dir__(self):
|
@@ -246,4 +249,4 @@ def cli():
|
|
246
249
|
SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
|
247
250
|
|
248
251
|
|
249
|
-
__version__ = "0.0.3"
|
252
|
+
__version__ = "0.0.3.1"
|
reactivity/primitives.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from collections.abc import Callable
|
2
|
-
from typing import Any
|
2
|
+
from typing import Any, Self, overload
|
3
3
|
from weakref import WeakKeyDictionary, WeakSet
|
4
4
|
|
5
5
|
|
@@ -79,7 +79,14 @@ class State[T](Signal[T]):
|
|
79
79
|
self._check_equality = check_equality
|
80
80
|
self.map = WeakKeyDictionary[Any, Signal[T]]()
|
81
81
|
|
82
|
+
@overload
|
83
|
+
def __get__(self, instance: None, owner: type) -> Self: ...
|
84
|
+
@overload
|
85
|
+
def __get__(self, instance: Any, owner: type) -> T: ...
|
86
|
+
|
82
87
|
def __get__(self, instance, owner):
|
88
|
+
if instance is None:
|
89
|
+
return self
|
83
90
|
try:
|
84
91
|
return self.map[instance].get()
|
85
92
|
except KeyError:
|
@@ -94,13 +101,13 @@ class State[T](Signal[T]):
|
|
94
101
|
state.set(value)
|
95
102
|
|
96
103
|
|
97
|
-
class
|
98
|
-
def __init__(self, fn: Callable[[], T],
|
104
|
+
class Effect[T](BaseComputation[T]):
|
105
|
+
def __init__(self, fn: Callable[[], T], call_immediately=True):
|
99
106
|
super().__init__()
|
100
107
|
|
101
108
|
self._fn = fn
|
102
109
|
|
103
|
-
if
|
110
|
+
if call_immediately:
|
104
111
|
self()
|
105
112
|
|
106
113
|
def trigger(self):
|
hmr-0.0.3.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
hmr-0.0.3.dist-info/METADATA,sha256=p98mCIdhqoduIMYRW_Lme7IlbZsfmzQ-czinyxdTzmo,228
|
2
|
-
hmr-0.0.3.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
-
hmr-0.0.3.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
|
4
|
-
reactivity/__init__.py,sha256=Stl2BBvqzutjcmF-O-olFTbSzJxzAl1xNMbu8mAVjlo,320
|
5
|
-
reactivity/functional.py,sha256=KAsqgPQsxIGuqO4BAtH6VF78MigLSBQ2k3aL4o_Vffg,1290
|
6
|
-
reactivity/helpers.py,sha256=auLTDFjfFc-cU9kVfm356GALW9lJIQ_UV7LGRZ2fWIw,3434
|
7
|
-
reactivity/hmr.py,sha256=VmFpw9OZV4yiO0LuNu2wRfN4q-QoDvhPSDdjjixR1e8,8543
|
8
|
-
reactivity/primitives.py,sha256=EIa_-5XOhffKw_lJ13EoAmFD3l0u_LFG1pJbODZSpMw,3351
|
9
|
-
hmr-0.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|