You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
698 B
Rust

6 years ago
#[macro_use]
extern crate seed;
use seed::prelude::*;
6 years ago
use wasm_bindgen::prelude::*;
// Model
6 years ago
#[derive(Clone)]
6 years ago
struct Model {
pub val: i32,
}
impl Default for Model {
fn default() -> Self {
Self {
val: 0,
}
}
}
6 years ago
6 years ago
// Update
6 years ago
#[derive(Clone)]
6 years ago
enum Msg {
Increment,
}
6 years ago
fn update(msg: &Msg, model: &Model) -> Model {
6 years ago
match msg {
Msg::Increment => Model {val: model.val + 1}
6 years ago
}
}
6 years ago
6 years ago
// View
fn view(model: &Model) -> El<Msg> {
button![
vec![simple_ev("click", Msg::Increment)],
format!("Hello, World × {}", model.val)
]
6 years ago
}
#[wasm_bindgen]
6 years ago
pub fn render() {
seed::run(Model::default(), update, view, "main");
6 years ago
}