Skip to main content

Crate dioxus_tea

Crate dioxus_tea 

Source
Expand description

Implementation of The Elm Architecture-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§

TeaModelSignal
A signal that holds the state of a TeaModel and provides an internal coroutine for processing actions.

Traits§

TeaModel
Trait representing a TEA model in Dioxus.

Functions§

use_tea_model
Creates a new TeaModelSignal for the given TeaModel.