1 unstable release

0.0.0 Jul 28, 2020

#7 in #div

MIT/Apache

3KB
54 lines

vdom

An elegant vdom inspired by SwiftUI.

use vdom::*;


pub struct TodoItem;

impl TodoItem {
  fn new(s:&str) -> VNode{
    view! {
      Div.add_class("todo-item"){
        Text(s)
      }
    }
  }
}

pub struct TodoList;

impl TodoList {
  fn new(todos:Vec<String>) -> VNode{
    view! {
      Div.add_class("todo-list"){
        For(i in todos.iter()) { TodoItem(i) }
      }
    }
  }
}

fn main() {
    let todos = vec![
      "drink coffee".to_string(),
      "write some code".to_string(),
      "eat lunch".to_string(),
    ];

    let list = TodoList::new(todos);

    println!("{}", list.render_to_string());
}

Dependencies

~3KB