Module savory::view[][src]

Traits used to build views.

Views

View is used to build HTML nodes, and since Savory is built on top of Seed, views should return Seed Node, the returned type can be anything actually, but it’s common to return single node (Node<Msg>) or collection of nodes (Vec<Node<Msg>>) depending on the view type.

Views can be any type that implement View trait, here is an example of view type:

Here is simple example on implementing View trait:

struct HomePage;

impl<Msg> View<Node<Msg>> for HomePage {
    fn view(&self) -> Node<Msg> {
        html::div().push("Home page")
    }
}

View Functions

Function and closure can be used where View is expected, Savory have blanket implementation for Fn() -> T, so we can use closure as view type:

let greeting = "Hello";
let greeting = || html::h1().push(greeting);
let node: Node<()> = greeting.view();

View types and View functions

View functions are simple to write and read and suitable for application code, while view types works well with reusable, complex elements.

Traits

View

Main trait used to render view.