Trait vizia_core::model::Model
source · pub trait Model: 'static + Sized {
// Provided methods
fn build(self, cx: &mut Context) { ... }
fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event) { ... }
fn name(&self) -> Option<&'static str> { ... }
}
Expand description
A trait implemented by application data in order to respond to events and mutate state.
§Examples
pub struct AppData {
count: i32,
}
enum AppEvent {
Increment,
Decrement,
}
impl Model for AppData {
fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
event.map(|app_event, _| match app_event {
AppEvent::Increment => {
self.count += 1;
}
AppEvent::Decrement => {
self.count -= 1;
}
});
}
}
Provided Methods§
sourcefn build(self, cx: &mut Context)
fn build(self, cx: &mut Context)
Build the model data into the application tree.
§Examples
fn main() {
Application::new(|cx|{
AppData::default().build(cx);
}).run();
}
sourcefn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event)
fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event)
Respond to events in order to mutate the model data.
§Examples
impl Model for AppData {
fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
event.map(|app_event, _| match app_event {
AppEvent::Increment => {
self.count += 1;
}
AppEvent::Decrement => {
self.count -= 1;
}
});
}
}
fn name(&self) -> Option<&'static str>
Object Safety§
This trait is not object safe.