1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use crate::Node;
pub use effects::Effects;
mod effects;
/// A component has a view and can update itself.
///
/// The update function returns an effect which can contain
/// follow ups and effects. Follow ups are executed on the next
/// update loop of this component, while the effects are executed
/// on the parent component that mounts it.
pub trait Component<MSG, PMSG> {
/// Update the model of this component and return
/// follow up and/or effects that will be executed on the next update loop
fn update(&mut self, msg: MSG) -> Effects<MSG, PMSG>;
/// the view of the component
fn view(&self) -> Node<MSG>;
/// optionally a Component can specify its own css style
fn style(&self) -> String {
String::new()
}
}
/// A Container have children that is set from the parent component
///
/// It can update its Mode and returns follow ups and/or effects on the next
/// update loop.
///
/// The view in the container is set by the parent component. The container itself
/// can not listen to events on its view
pub trait Container<MSG, PMSG> {
/// update the model of this component and return follow ups and/or effects
/// that will be executed on the next update loop.
fn update(&mut self, msg: MSG) -> Effects<MSG, PMSG>;
/// The container presents the children passed to it from the parent.
/// The container can decide how to display the children components here, but
/// the children nodes here can not trigger Msg that can update this component
fn view(&self) -> Node<PMSG>;
/// optionally a Container can specify its own css style
fn style(&self) -> String {
String::new()
}
}
/// Just a view, no events, no update.
/// The properties of the component is set directly from the parent
pub trait View<MSG> {
/// only returns a view of itself
fn view(&self) -> Node<MSG>;
/// optionally a View can specify its own css style
fn style(&self) -> String {
String::new()
}
}