| Crates.io | dioxus-tea |
| lib.rs | dioxus-tea |
| version | 0.1.5 |
| created_at | 2025-06-26 06:13:48.277569+00 |
| updated_at | 2025-06-26 09:06:06.927668+00 |
| description | Dioxus - The Elm Architecture (TEA) Model |
| homepage | |
| repository | https://github.com/mibes404/dioxus_tea.git |
| max_upload_size | |
| id | 1726863 |
| size | 226,968 |
People may also know this as the "Model-Update-View" architecture, or redux-like architecture. The benefit of this architecture is that it allows you to manage your application state in a predictable way, making it easier to reason about and test.
The model is built in such a way that you can use regular Rust unit tests to test your application logic, i.e. validate
the update function of your model.
Include the dependency in your Cargo.toml:
dioxus-tea = "0.1"
A complete example can be found in the examples/tea-time directory.
Usage:
#[derive(Default, Clone, PartialEq)]
pub struct AppState {
pub status: Status,
}
pub enum AppStatusUpdate {
CupFetched,
AddWater(u8),
AddTeaBag(TeaType),
Done,
}
impl TeaModel for AppState {
type Action = AppStatusUpdate;
fn update(&mut self, action: Self::Action) {
match action {
// handle actions and update the state accordingly
AppStatusUpdate::CupFetched => {
// when the cup is fetched, we start with an empty cup
self.status = Status::EmptyCup;
}
// other actions
}
}
}
#[component]
pub fn App() -> Element {
let app_state = use_tea_model::<AppState>();
app_state.send(AppStatusUpdate::CupFetched);
}
A unit test could look like this:
#[test]
fn confirm_that_we_can_only_add_a_tea_bag_when_we_have_a_cup() {
let mut app_state = AppState::default();
app_state.update(AppStatusUpdate::AddTeaBag(TeaType::Black));
assert_eq!(
app_state.status,
Status::Error(MakeTeaError::NoCup),
"Cannot add a tea bag without a cup"
);
}
dx serve --platform web --example tea-time