Reactive
SyncState
¶
Reactive
¶
Bases: Generic[Context_T]
Base class of all reactive types.
Mostly useful for type checks, e.g. isinstance(value, Reactive). It can't be
instantiated or subclassed directly. Reactive dataclasses don't inherit from it:
check them with is_sync_dataclass.
A reactive object is either inert, live, or dead (see SyncState).
Example:
from syncwave import Reactive, SyncDict, Syncwave
syncwave = Syncwave()
sync_dict = syncwave.create_store(SyncDict[str, int], name="sync_dict")
print(isinstance(sync_dict, Reactive)) # True
print(issubclass(SyncDict, Reactive)) # True
Usage Documentation
Source code in src/syncwave/reactive.py
109 110 111 112 | |
sync_live
property
¶
sync_live: bool
Whether this object is live, i.e. connected to a store.
False for both inert and dead objects. Use sync_state to tell them apart.
Example:
from syncwave import SyncModel, Syncwave
syncwave = Syncwave()
@syncwave.store(name="customers")
class Customer(SyncModel):
name: str
age: int
customers = syncwave["customers"]
customers.append({"name": "Alice", "age": 30})
alice = customers[0]
print(alice.sync_live) # True
del customers[0]
print(alice.sync_live) # False