dioxus-tea 0.1.0

Dioxus - The Elm Architecture (tea) Model
Documentation

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);
}