diff --git a/Cargo.lock b/Cargo.lock index 23fd02b..ec82e67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -178,7 +178,7 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "concoct" version = "0.10.1" -source = "git+https://github.com/concoct-rs/concoct#d460fd10ee93511d810914e2591bddef103fd406" +source = "git+https://github.com/concoct-rs/concoct#fe809ce828f99d71dd88e9e615adc93567e2127c" dependencies = [ "futures", "hashbrown", diff --git a/src/web/mod.rs b/src/web/mod.rs index 03efe41..a86cf8c 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,4 +1,4 @@ -use concoct::{Handle, Object, Slot}; +use concoct::{Handle, Object, Slot, Signal}; use web_sys::wasm_bindgen::JsCast; pub trait View { @@ -59,9 +59,7 @@ pub struct MouseEvent; pub struct ElementBuilder {} impl ElementBuilder { - pub fn on_click(&mut self, _f: Handle>) -> &mut Self { - self - } + pub fn child(&mut self, _view: impl ViewGroup) -> &mut Self { self @@ -108,6 +106,10 @@ impl View for Element { } } +impl Signal for Element { + +} + pub struct AppendChild(pub Handle); impl Slot> for Element { diff --git a/web-examples/src/main.rs b/web-examples/src/main.rs index 443c374..4d7cf94 100644 --- a/web-examples/src/main.rs +++ b/web-examples/src/main.rs @@ -1,5 +1,5 @@ use concoct::{Handle, Object, Slot}; -use viewbuilder::web::{self, Element, Text}; +use viewbuilder::web::{Element, Text}; #[derive(Clone, Copy)] enum Message { @@ -24,17 +24,10 @@ impl Slot for Counter { } } -struct CounterButton { - msg: Message, - counter: Handle, -} - -impl Object for CounterButton {} - -impl Slot for CounterButton { - fn handle(&mut self, _cx: concoct::Handle, _msg: web::MouseEvent) { - self.counter.send(self.msg); - } +fn counter_button(counter: &Handle, label: &str, msg: Message) -> Handle { + let button = Element::builder().child(Text::new(label)).build().start(); + button.map(&counter, move |_| msg); + button } #[viewbuilder::main] @@ -47,28 +40,11 @@ fn main() { } .start(); - let increment_button = CounterButton { - msg: Message::Increment, - counter: counter.clone(), - } - .start(); - let decrement_button = CounterButton { - msg: Message::Decrement, - counter, - } - .start(); - Element::builder() .child(( text, - Element::builder() - .on_click(increment_button) - .child(Text::new("Up High!")) - .build(), - Element::builder() - .on_click(decrement_button) - .child(Text::new("Down Low!")) - .build(), + counter_button(&counter, "Up high!", Message::Increment), + counter_button(&counter, "Down low!", Message::Decrement), )) .build() .start();