Function sauron::prelude::view_if

source ·
pub fn view_if<MSG>(flag: bool, node: Node<MSG>) -> Node<MSG>
Expand description

A help function which render the view when the condition is met, otherwise just display a span(vec![], vec![])

§Examples

use sauron::*;

let content = "hello world";
let html: Node<()> = view_if(!content.is_empty(), p(vec![], vec![text(content)]));

assert_eq!(node!{<p>"hello world"</p>}, html);

Note: that the node here is already evaluated therefore not suitable for building the nodes prior and will end up not being displayed. An alternative would be to just use if else statement like so:

if flag{
    expensive_code_to_build_the_view()
}else{
    comment("not yet ready")
}