Syncwave
Syncwave
¶
Bases: MutableMapping[str, Any], Reactive
The main entry point to Syncwave.
Start by creating an instance to interact with the stores.
Example:
from syncwave import Syncwave
syncwave = Syncwave()
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
str | Path
|
Directory holding the stores' JSON files. Created if it doesn't exist. |
'syncstores'
|
Source code in src/syncwave/syncwave.py
79 80 81 82 83 84 85 86 87 88 89 90 | |
root_path
property
¶
root_path: Path
The absolute path to the directory holding the stores' JSON files.
Usage Documentation
create_store
¶
Create a store, persisted to <root_path>/<name>.json and two-way synced.
Every change to the store, from Python or from the file, is validated against
tp.
Example:
from syncwave import SyncSet, Syncwave
syncwave = Syncwave()
tags = syncwave.create_store(SyncSet[str], name="tags")
tags.add("python")
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
TypeForm[T]
|
Type of the store, e.g. |
required |
name
|
str
|
Name of the store, used as its key and as its file name. |
required |
default
|
Any
|
Initial value, used if the file is missing or empty. Required when
no empty value ( |
void
|
Returns:
| Type | Description |
|---|---|
T
|
The store's value: the live object for a reactive type, a copy otherwise. |
Source code in src/syncwave/syncwave.py
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 | |
store
¶
store(
*,
name: str,
collection: type[SyncDict[Any, Never] | SyncList[Never]]
| Literal["auto"]
| None = "auto",
default: Any = void,
) -> Callable[
[type[SyncModelLike_T]], type[SyncModelLike_T]
]
Class decorator creating a store from a reactive model.
Like create_store, but the model is wrapped in a collection first (see
collection). The class is returned unchanged.
Example:
from syncwave import SyncModel, Syncwave
syncwave = Syncwave()
@syncwave.store(name="customers")
class Customer(SyncModel):
name: str
age: int
customers = syncwave["customers"] # a SyncList[Customer]
customers.append(Customer(name="Alice", age=30))
Usage Documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the store, used as its key and as its file name. |
required |
collection
|
type[SyncDict[Any, Never] | SyncList[Never]] | Literal['auto'] | None
|
|
'auto'
|
default
|
Any
|
Initial value, used if the file is missing or empty. Pass plain
data (e.g. a |
void
|
Returns:
| Type | Description |
|---|---|
Callable[[type[SyncModelLike_T]], type[SyncModelLike_T]]
|
A decorator that creates the store and returns the class unchanged. |
Source code in src/syncwave/syncwave.py
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 | |