Expand description
Implementation of the Tea-model for Dioxus.
Example usage 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);
}Structs§
- TeaModel
Signal - A signal that holds the state of a
TeaModeland provides an internal coroutine for processing actions.
Traits§
- TeaModel
- Trait representing a TEA model in Dioxus.
Functions§
- use_
tea_ model - Creates a new
TeaModelSignalfor the givenTeaModel.