diff --git a/README.md b/README.md index a8387e9c..337719f1 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ fn main () {
{ "Hey :)" }
diff --git a/crates/virtual-dom-rs/Cargo.toml b/crates/virtual-dom-rs/Cargo.toml index 85716174..e31b4dc4 100644 --- a/crates/virtual-dom-rs/Cargo.toml +++ b/crates/virtual-dom-rs/Cargo.toml @@ -27,6 +27,7 @@ features = [ "NodeList", "Text", "Window", + "Event", "MouseEvent", "InputEvent", ] @@ -37,7 +38,6 @@ wasm-bindgen-test = "0.2" [dev-dependencies.web-sys] version = "0.3" features = [ - "Event", "DomTokenList", "HtmlInputElement", ] diff --git a/crates/virtual-dom-rs/src/html_macro.rs b/crates/virtual-dom-rs/src/html_macro.rs index 8125416f..7b79c133 100644 --- a/crates/virtual-dom-rs/src/html_macro.rs +++ b/crates/virtual-dom-rs/src/html_macro.rs @@ -42,7 +42,7 @@ pub enum TagType { /// use virtual_dom_rs::VirtualNode; /// /// let click_message = "I was clicked!"; -/// let some_component = html! {
}; +/// let some_component = html! {
}; /// /// // Create lists of nodes from data! /// let list: Vec = [0, 1, 2].iter().map(|index| { @@ -57,7 +57,7 @@ pub enum TagType { /// }).collect(); /// /// let root_node = html! { -///
+///
/// { "Hello world" } /// { "How are" "you?" } /// @@ -203,7 +203,7 @@ macro_rules! recurse_html { // Closure::wrap is not implemented on non wasm32 targets #[cfg(target_arch = "wasm32")] { - let closure = $crate::Closure::wrap(Box::new($callback) as Box); + let closure = $crate::Closure::wrap(Box::new($callback) as Box); $active_node.as_mut().unwrap().borrow_mut().custom_events.0.insert( stringify!($event_name).to_string(), @@ -314,7 +314,7 @@ mod tests { fn event() { test(HTMLMacroTest { generated: html!{ -
+
}, expected: html!{
}, desc: "Events are ignored in non wasm-32 targets", diff --git a/crates/virtual-dom-rs/tests/create_element.rs b/crates/virtual-dom-rs/tests/create_element.rs index 1f699603..2fe07aae 100644 --- a/crates/virtual-dom-rs/tests/create_element.rs +++ b/crates/virtual-dom-rs/tests/create_element.rs @@ -39,7 +39,7 @@ fn click_event() { let div = html! {
diff --git a/crates/virtual-dom-rs/tests/events.rs b/crates/virtual-dom-rs/tests/events.rs index 871300a0..242c61b1 100644 --- a/crates/virtual-dom-rs/tests/events.rs +++ b/crates/virtual-dom-rs/tests/events.rs @@ -14,6 +14,39 @@ extern crate virtual_dom_rs; wasm_bindgen_test_configure!(run_in_browser); +#[wasm_bindgen_test] +fn on_input_custom() { + let text = Rc::new(RefCell::new("Start Text".to_string())); + let text_clone = Rc::clone(&text); + + let input = html! { + > value to the input elements value + !oninput=move |event: Event| { + let input_elem = event.target().unwrap(); + + let input_elem = input_elem.dyn_into::().unwrap(); + + *text_clone.borrow_mut() = input_elem.value(); + }, + value="End Text", + > + + }; + + let input_event = InputEvent::new("input").unwrap(); + let input = input.create_element(); + + assert_eq!(&*text.borrow(), "Start Text"); + + // After dispatching the oninput event our `text` should have a value of the input elements value. + (web_sys::EventTarget::from(input)) + .dispatch_event(input_event.as_ref() as &web_sys::Event) + .unwrap(); + + assert_eq!(&*text.borrow(), "End Text"); +} + #[wasm_bindgen_test] fn on_input() { let text = Rc::new(RefCell::new("Start Text".to_string())); diff --git a/crates/virtual-node/Cargo.toml b/crates/virtual-node/Cargo.toml index 729d2bb5..c2e02f62 100644 --- a/crates/virtual-node/Cargo.toml +++ b/crates/virtual-node/Cargo.toml @@ -21,6 +21,7 @@ features = [ "NodeList", "Text", "Window", + "Event", "MouseEvent", "InputEvent", ] diff --git a/crates/virtual-node/src/lib.rs b/crates/virtual-node/src/lib.rs index cff75e9e..fa7e0684 100644 --- a/crates/virtual-node/src/lib.rs +++ b/crates/virtual-node/src/lib.rs @@ -383,7 +383,7 @@ impl fmt::Display for VirtualNode { /// We need a custom implementation of fmt::Debug since FnMut() doesn't /// implement debug. -pub struct CustomEvents(pub HashMap ()>>>>); +pub struct CustomEvents(pub HashMap ()>>>>); impl PartialEq for CustomEvents { // TODO: What should happen here..? And why? @@ -408,7 +408,7 @@ mod tests { // #[test] // fn to_string() { // let node = html! { -//
+//
// // { "Hello world" } // diff --git a/examples/isomorphic/app/src/views/home_view.rs b/examples/isomorphic/app/src/views/home_view.rs index 2d271690..4cd8d488 100644 --- a/examples/isomorphic/app/src/views/home_view.rs +++ b/examples/isomorphic/app/src/views/home_view.rs @@ -35,7 +35,7 @@ impl View for HomeView { { nav_bar } { "The button has been clicked: " click_component " times!"} - +
{ "In this time Ferris has made " click_count " new friends." }
diff --git a/examples/isomorphic/app/src/views/nav_bar_view/nav_bar_item_view.rs b/examples/isomorphic/app/src/views/nav_bar_view/nav_bar_item_view.rs index 7fb7f2a7..17e8e180 100644 --- a/examples/isomorphic/app/src/views/nav_bar_view/nav_bar_item_view.rs +++ b/examples/isomorphic/app/src/views/nav_bar_view/nav_bar_item_view.rs @@ -38,7 +38,7 @@ impl View for NavBarItemView {