Stores¶
Stores implement Python's read-only collection protocols; synchronous scoped drafts implement their mutable counterparts. See the store guide for versions, identity, snapshots, projections, and optimistic rebasing.
store
¶
Transactional, entity-based reactive mappings and sequences.
A setter opens a scoped mutable draft. Successful synchronous edits are
staged together and become visible at the next flush. Read proxies retain
entity identity through moves; dictionary methods have normal Python
semantics. Use subscription for keys such as items or get.
Classes:
| Name | Description |
|---|---|
DraftExpiredError |
A draft was used after its setter or deriving function finished. |
Store |
Read-only reactive mapping with optional attribute access to data keys. |
StoreList |
Read-only reactive sequence. Entity proxies survive reorders. |
Draft |
A mapping draft that expires when its callback returns. |
DraftList |
A sequence draft with standard Python mutation methods. |
StoreSetter |
Apply an atomic draft edit. Exceptions discard all changes from the call. |
Functions:
| Name | Description |
|---|---|
create_store |
Create a reactive mapping or sequence and its atomic draft setter. |
create_projection |
Create a read-only derived store with memo readiness and refresh semantics. |
create_optimistic_store |
Layer optimistic draft edits over a reactive authoritative source. |
reconcile |
Prepare replacement data, preserving matched list entity identities. |
snapshot |
Return a detached, untracked copy of the currently visible state. |
deep |
Return a detached snapshot, tracking changes only within this subtree. |
DraftExpiredError
¶
Bases: RuntimeError
A draft was used after its setter or deriving function finished.
ListChange
dataclass
¶
Internal sequence edit. Indices refer to the state before this edit.
Store
¶
Bases: _Proxy, Mapping[str, Any]
Read-only reactive mapping with optional attribute access to data keys.
Missing subscriptions raise KeyError; missing attributes raise AttributeError.
Mapping methods take precedence over data keys: use store["items"].
Methods:
| Name | Description |
|---|---|
get |
Return the value for |
StoreList
¶
Draft
¶
DraftList
¶
Bases: StoreList[T], MutableSequence[T]
A sequence draft with standard Python mutation methods.
Methods:
| Name | Description |
|---|---|
insert |
Insert a value at a draft index. |
extend |
Append values in one recorded splice. |
clear |
Remove all items in one transactional edit. |
sort |
Sort entities without changing their identities. |
reverse |
Reverse entity order in the draft. |
move |
Move a contiguous range to a final index, preserving its entities. |
sort
¶
Sort entities without changing their identities.
StoreSetter
¶
Apply an atomic draft edit. Exceptions discard all changes from the call.
create_store
¶
create_store(initial: list[T], seed: None = None) -> tuple[StoreList[T], StoreSetter[DraftList[T]]]
create_store(initial: S, seed: None = None) -> tuple[Store[S], StoreSetter[Draft[S]]]
create_store(initial: Any, seed: Any = None) -> tuple[Any, StoreSetter]
Create a reactive mapping or sequence and its atomic draft setter.
A deriving function may return data or mutate its draft, synchronously or asynchronously. Its reads are tracked and its writes are staged together.
create_projection
¶
Create a read-only derived store with memo readiness and refresh semantics.
create_optimistic_store
¶
Layer optimistic draft edits over a reactive authoritative source.
Active edits replay in submission order when the source changes. They are removed when their submitting action settles; other actions keep their edits. Draft callbacks must be deterministic: replay mustn't perform network or other side effects.
reconcile
¶
Prepare replacement data, preserving matched list entity identities.
key names the field that identifies list entities ("id" by
default), or is a function computing the identity from an entity.
key=None replaces list entities positionally. Duplicate keys are
matched in occurrence order, without assigning the same entity to
multiple rows.
snapshot
¶
Return a detached, untracked copy of the currently visible state.