-
-
Notifications
You must be signed in to change notification settings - Fork 57
application
A minimal sauron application only need to implement the Application
trait.
pub trait Application<MSG>{
fn update(&mut self, msg: MSG) -> Cmd<Self, MSG>;
fn view(&self) -> Node<MSG>;
}
impl Application<Msg> for Model {
fn update(&mut self, msg: MSG) -> Cmd<Self, MSG>{
// --snip--
}
fn view(&self) -> Node<MSG>{
// --snip
}
}
There are only 2 methods that you are required to implement in an Application.
The update
function describes how it update the models based on the MSG
that
is coming from UI events. Update can return a Cmd
which in turn further update the
Application model in the subsequent update loop.
The view
function describes how to present the application in the screen.
Sauron has a runtime system where it executes commands.
A Cmd
is a way of telling Sauron, "Hey, I want you to do this thing!".
So if you want to send an HTTP request, you would need to command Sauron to do it.
Every Cmd
specifis which effects you need to do the application and the type of messages that will come back into your application.