silk.machine.store.
Stores: a context and one function that changes it for each event.
When to use#
Use a store for state that has no modes: a counter, a form, a cart. Implement Reducer
for the context, start the store with Stores.begin and send it events with
Stores.send. Reach for a machine when what an event does depends on a state.
Details#
A store is a machine with one state, Only, so a Store is a Snapshot. It is written
to JSON and read back like any snapshot, and Actors and Durable run it and perform the
effects its reducer queues.
Import as Stores with import silk.machine.store { Stores }.
Public declarations: 4.
Only#
pub union Only<C>The one state of a store whose context is C.
Active#
ActiveImplementation Schema for Only<C>#
impl<C> Schema for Only<C>Reducer#
pub interface Reducer<E, X>A context that changes itself for each event of type E and can queue effects of type X.
Operation reduce#
effect fn reduce(self: &mut Self, event: &E, enq: &mut Enqueue<E, X>) -> ()
! OutOfMemoryError
? &mut AllocatorApplies event to the context. enq takes effects to perform and events to process
next.
Implementation Machine<E, C, X> for Only<C>#
impl<E, C: Reducer<E, X>, X> Machine<E, C, X> for Only<C>Operation chart#
static fn chart() -> Chart<Only<C>, E, C, X>Operation handle#
effect fn handle(state: &Only<C>, context: &mut C, event: &E, enq: &mut Enqueue<E, X>) -> Next<
Only<C>
>
! OutOfMemoryError
? &mut AllocatorStore#
pub type Store<E, C, X> = Snapshot<Only<C>, E, C, X>A store of events E, context C and effects X. The context is store.context.
Stores#
pub struct StoresImplementation Stores#
impl StoresAssociated function begin#
pub effect fn begin<E, C: Reducer<E, X>, X>(context: C) -> Store<E, C, X>
! OutOfMemoryError | TransitionLoopError
? &mut AllocatorReturns a store that starts with context.
Associated function send#
pub effect fn send<E, C: Reducer<E, X>, X>(store: &mut Store<E, C, X>, event: E) -> ()
! OutOfMemoryError | TransitionLoopError
? &mut AllocatorApplies event to the store, then every event the reducer raised. Effects the reducer
queued wait in store.pending. Use Actors.send in its place to perform them.
Category: State machines.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.