SyncCollection
SyncCollection
¶
Bases: Reactive
Virtual base class of SyncDict, SyncList, and SyncSet.
Meant for isinstance and issubclass checks. It can't be instantiated or
subclassed.
Example:
from syncwave import SyncCollection, SyncList, Syncwave
syncwave = Syncwave()
sync_list = syncwave.create_store(SyncList[int], name="sync_list")
print(isinstance(sync_list, SyncCollection)) # True
print(issubclass(SyncList, SyncCollection)) # True
Usage Documentation
Source code in src/syncwave/reactive.py
109 110 111 112 | |
SyncDict
¶
Bases: MutableMapping[KT, VT], Reactive[SyncDictCtx[KT, VT]]
The reactive counterpart of dict.
When live, every change is validated and written to the JSON file, and changes to
the file are applied in place. Created directly, it's inert and acts like a dict.
Example:
from syncwave import SyncDict, Syncwave
syncwave = Syncwave()
sync_dict = syncwave.create_store(SyncDict[str, int], name="sync_dict")
sync_dict["a"] = 1
sync_dict["b"] = 2
sync_dict["c"] = 3
print(sync_dict)
print(list(sync_dict.items()))
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[KT, VT] | Iterable[tuple[KT, VT]]
|
A mapping, or an iterable of key/value pairs. |
()
|
**kwargs
|
VT
|
Additional entries. |
{}
|
Source code in src/syncwave/sync_collection.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
SyncList
¶
SyncList(iterable: Iterable[VT] = ())
Bases: MutableSequence[VT], Reactive[SyncListCtx[VT]]
The reactive counterpart of list.
When live, every change is validated and written to the JSON file, and changes to
the file are applied in place. Created directly, it's inert and acts like a list.
References to reactive items follow positions, not content. Slices aren't supported yet.
Example:
from syncwave import SyncList, Syncwave
syncwave = Syncwave()
sync_list = syncwave.create_store(SyncList[int], name="sync_list")
sync_list.append(1)
sync_list.extend([2, 3])
print(sync_list)
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable
|
Iterable[VT]
|
Initial items. |
()
|
Source code in src/syncwave/sync_collection.py
389 390 391 392 393 394 395 396 | |
SyncSet
¶
SyncSet(iterable: Iterable[VT] = ())
Bases: MutableSet[VT], Reactive[SyncSetCtx[VT]]
The reactive counterpart of set.
When live, every change is validated and written to the JSON file (as an array),
and changes to the file are applied in place. Created directly, it's inert and acts
like a set.
Items must be hashable, so they can't be reactive.
Example:
from syncwave import SyncSet, Syncwave
syncwave = Syncwave()
sync_set: SyncSet[int] = syncwave.create_store(SyncSet[int], name="sync_set")
sync_set.add(1)
sync_set.add(2)
sync_set.discard(2)
print(sync_set)
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable
|
Iterable[VT]
|
Initial items. |
()
|
Source code in src/syncwave/sync_collection.py
650 651 652 653 654 655 656 657 | |