1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! Traits to implement on a model to allow it to interact with an application.

use crate::app::side_effect::Commands;

/// Process a message that updates the model.
pub trait Update<Message, Command = ()> {
    /// Update the model using the given message. Implement this to describe the behavior of your
    /// app.
    fn update(&mut self, msg: Message, _commands: &mut Commands<Command>) {
        self.simple_update(msg);
    }

    /// Update the model using the given message. Implement this if your app does not need to use
    /// side effecting commands.
    fn simple_update(&mut self, _msg: Message) { }
}

impl<M> Update<(), ()> for M { }

/// Render (or view) the model as a virtual dom.
pub trait Render<DomTree> {
    /// Render the model as a virtual dom.
    fn render(&self) -> DomTree;
}