Fix examples

This commit is contained in:
Denis Kolodin 2018-01-01 12:15:07 +03:00
parent e74a93dc4d
commit 3b2dbc5a98
2 changed files with 17 additions and 7 deletions

View File

@ -9,6 +9,10 @@ use std::time::Duration;
use yew::services::Task;
use yew::services::interval::IntervalService;
struct Context {
interval: IntervalService<Msg>,
}
#[derive(Clone, Copy, PartialEq)]
enum LifeState {
Live,
@ -141,14 +145,14 @@ enum Msg {
ToggleCellule(usize)
}
fn update(context: &mut Context<Msg>, gof: &mut GameOfLife, msg: Msg) {
fn update(context: &mut Context, gof: &mut GameOfLife, msg: Msg) {
match msg {
Msg::Random => {
gof.random_mutate();
println!("Random");
},
Msg::Start => {
let handle = context.interval(Duration::from_millis(200), || Msg::Step);
let handle = context.interval.spawn(Duration::from_millis(200), || Msg::Step);
gof.job = Some(Box::new(handle));
println!("Start");
},
@ -211,12 +215,15 @@ fn view_cellule((idx, cellule): (usize, &Cellule)) -> Html<Msg> {
}
fn main() {
let mut app = App::new();
let context = Context {
interval: IntervalService::new(app.sender()),
};
let gof = GameOfLife {
cellules: vec![Cellule { life_state: LifeState::Dead }; 2000],
cellules_width: 50,
cellules_height: 40,
job : None
};
program(gof, update, view);
}
app.run(context, gof, update, view);
}

View File

@ -63,7 +63,7 @@ enum Msg {
Nope,
}
fn update(_: &mut Context<Msg>, model: &mut Model, msg: Msg) {
fn update(_: &mut Context, model: &mut Model, msg: Msg) {
match msg {
Msg::Add => {
let entry = Entry {
@ -207,14 +207,17 @@ fn view_entry_edit_input((idx, entry): (usize, &Entry)) -> Html<Msg> {
}
}
struct Context;
fn main() {
let mut app = App::new();
let model = Model {
entries: Vec::new(),
filter: Filter::All,
value: "".into(),
edit_value: "".into(),
};
program(model, update, view);
app.run(Context, model, update, view);
}