The Elm Architecture for leptos.
This crate is a particular strategy for state management in leptos`. It follows the Elm architecture, but not strictly so, which allows mixing and matching with other state management approaches.
First, let's look at an example.
Example
use *;
use Cmd;
In the above example, we're annotating CounterModel with
leptos_tea::Model, which will derive a few important things:
# use *;
# use Cmd;
// Original struct, stays as-is
// Model passed to the update function
// model passed to the component when you call `.init()`
You first need to create your CounterModel, however you'd like.
In this case, we're using Default. Then you call .init(),
which will return a tuple containing the read-only model, as well
as a MsgDispatcher, which allows you to do msg_dispatcher(Msg::Blah)
on nightly, or msg_dispatcher.dispatch(Msg::Blah) on stable.
And that's how this crate and state management approach works.
Model nesting
Models can be nested inside one another like thus:
;
Limitations
leptos_tea::Model currently only supports tuple and field structs.
Enum support will be added soon.