from reactivity.collections import *¶
Tracking and mutation¶
reactive() dispatches by input type. Mutable mappings, sets, and sequences are proxied, so writes through the wrapper also change the original. The corresponding ReactiveMapping, ReactiveSet, and ReactiveSequence constructors create shallow copies instead. Other objects are handled by reactive_object_proxy.
- Mapping reads track keys. Changing an unrelated key does not rerun a computation that only reads one key. Iterating keys or reading length tracks structural changes.
- Set membership reads track the requested member.
- Sequence reads track indices; structural edits can affect several indices.
- Nested dictionaries, lists, and object values remain ordinary values unless separately wrapped.
Mutate through the wrapper. Direct writes to the original container bypass notification and can also leave the wrapper's structural bookkeeping out of date.
Current limitations¶
In hmr 0.7.6.3, sequence slices with a step other than 1 raise NotImplementedError. Object proxies require an instance __dict__; objects using only __slots__ are not supported. Collection iteration/length tracking uses the default context internally in this version, so custom-context collections should not be assumed to provide fully isolated structural tracking.
ReactiveMappingProxy
¶
Bases: MutableMapping[K, V]
Source code in reactivity/collections.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
context
instance-attribute
¶
context = context or default_context
_check_equality
instance-attribute
¶
_check_equality = check_equality
_data
instance-attribute
¶
_data = initial
_keys
instance-attribute
¶
_keys = defaultdict(
self._signal,
{k: self._signal(True) for k in tuple(initial)},
)
_iter
instance-attribute
¶
_iter = Subscribable()
_signal
¶
_signal(value=False)
Source code in reactivity/collections.py
11 12 |
|
__init__
¶
__init__(
initial: MutableMapping[K, V],
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
14 15 16 17 18 19 |
|
__getitem__
¶
__getitem__(key: K)
Source code in reactivity/collections.py
21 22 23 24 |
|
__setitem__
¶
__setitem__(key: K, value: V)
Source code in reactivity/collections.py
26 27 28 29 30 31 32 33 34 35 36 |
|
__delitem__
¶
__delitem__(key: K)
Source code in reactivity/collections.py
38 39 40 41 42 43 44 |
|
__iter__
¶
__iter__()
Source code in reactivity/collections.py
46 47 48 49 50 |
|
__len__
¶
__len__()
Source code in reactivity/collections.py
52 53 54 |
|
__repr__
¶
__repr__()
Source code in reactivity/collections.py
56 57 |
|
ReactiveMapping
¶
Bases: ReactiveMappingProxy[K, V]
Source code in reactivity/collections.py
60 61 62 |
|
__init__
¶
__init__(
initial: Mapping[K, V] | None = None,
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
61 62 |
|
ReactiveSetProxy
¶
Bases: MutableSet[T]
Source code in reactivity/collections.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
context
instance-attribute
¶
context = context or default_context
_check_equality
instance-attribute
¶
_check_equality = check_equality
_data
instance-attribute
¶
_data = initial
_items
instance-attribute
¶
_items = defaultdict(
self._signal,
{k: self._signal(True) for k in tuple(initial)},
)
_iter
instance-attribute
¶
_iter = Subscribable()
_signal
¶
_signal(value=False)
Source code in reactivity/collections.py
66 67 |
|
__init__
¶
__init__(
initial: MutableSet[T],
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
69 70 71 72 73 74 |
|
__contains__
¶
__contains__(value)
Source code in reactivity/collections.py
76 77 |
|
add
¶
add(value)
Source code in reactivity/collections.py
79 80 81 82 83 |
|
discard
¶
discard(value)
Source code in reactivity/collections.py
85 86 87 88 89 90 |
|
remove
¶
remove(value)
Source code in reactivity/collections.py
92 93 94 95 96 97 98 99 |
|
__iter__
¶
__iter__()
Source code in reactivity/collections.py
101 102 103 104 105 |
|
__len__
¶
__len__()
Source code in reactivity/collections.py
107 108 109 |
|
__repr__
¶
__repr__()
Source code in reactivity/collections.py
111 112 |
|
ReactiveSet
¶
Bases: ReactiveSetProxy[T]
Source code in reactivity/collections.py
115 116 117 |
|
__init__
¶
__init__(
initial: Set[T] | None = None,
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
116 117 |
|
ReactiveSequenceProxy
¶
Bases: MutableSequence[T]
Source code in reactivity/collections.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
context
instance-attribute
¶
context = context or default_context
_check_equality
instance-attribute
¶
_check_equality = check_equality
_data
instance-attribute
¶
_data = initial
_keys
instance-attribute
¶
_keys = defaultdict(self._signal)
_iter
instance-attribute
¶
_iter = Subscribable()
_length
instance-attribute
¶
_length = len(initial)
_signal
¶
_signal()
Source code in reactivity/collections.py
130 131 |
|
__init__
¶
__init__(
initial: MutableSequence[T],
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
133 134 135 136 137 138 139 140 141 142 |
|
__getitem__
¶
__getitem__(key: int) -> T
__getitem__(key: slice) -> list[T]
Source code in reactivity/collections.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
_replace
¶
_replace(range_slice: slice, target: Iterable[T])
Source code in reactivity/collections.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
__len__
¶
__len__()
Source code in reactivity/collections.py
250 251 252 |
|
__setitem__
¶
__setitem__(key, value)
Source code in reactivity/collections.py
254 255 256 257 258 259 260 261 262 |
|
__delitem__
¶
__delitem__(key)
Source code in reactivity/collections.py
264 265 266 267 268 269 270 271 272 |
|
insert
¶
insert(index, value)
Source code in reactivity/collections.py
274 275 276 277 278 279 280 281 |
|
append
¶
append(value)
Source code in reactivity/collections.py
283 284 |
|
extend
¶
extend(values)
Source code in reactivity/collections.py
286 287 |
|
pop
¶
pop(index=-1)
Source code in reactivity/collections.py
289 290 291 292 293 294 295 296 |
|
remove
¶
remove(value)
Source code in reactivity/collections.py
298 299 300 301 302 303 |
|
clear
¶
clear()
Source code in reactivity/collections.py
305 306 |
|
reverse
¶
reverse()
Source code in reactivity/collections.py
308 309 |
|
sort
¶
sort(*, key=None, reverse=False)
Source code in reactivity/collections.py
311 312 |
|
__repr__
¶
__repr__()
Source code in reactivity/collections.py
314 315 |
|
__eq__
¶
__eq__(value)
Source code in reactivity/collections.py
317 318 |
|
ReactiveSequence
¶
Bases: ReactiveSequenceProxy[T]
Source code in reactivity/collections.py
321 322 323 |
|
__init__
¶
__init__(
initial: Sequence[T] | None = None,
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
322 323 |
|
_weak_derived
¶
_weak_derived[T](
fn: Callable[[], T],
check_equality=True,
*,
context: Context | None = None,
)
Source code in reactivity/collections.py
120 121 122 123 124 125 126 |
|
reactive_object_proxy
¶
reactive_object_proxy[T](
initial: T,
check_equality=True,
*,
context: Context | None = None,
) -> T
Source code in reactivity/collections.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
reactive
¶
reactive[K, V](
value: MutableMapping[K, V],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveMappingProxy[K, V]
reactive[K, V](
value: Mapping[K, V],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveMapping[K, V]
reactive[T](
value: MutableSet[T],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveSetProxy[T]
reactive[T](
value: Set[T],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveSet[T]
reactive[T](
value: MutableSequence[T],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveSequenceProxy[T]
reactive[T](
value: Sequence[T],
check_equality=True,
*,
context: Context | None = None,
) -> ReactiveSequence[T]
reactive[T](
value: T,
check_equality=True,
*,
context: Context | None = None,
) -> T
Source code in reactivity/collections.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|