Skip to content

Commit

Permalink
temp fix on some event binding; tag 0.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jul 30, 2024
1 parent bf8c7bd commit 7880f6b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion respo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "respo"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
description = "a tiny virtual DOM library migrated from ClojureScript"
license = "Apache-2.0"
Expand Down
98 changes: 78 additions & 20 deletions respo/src/app/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use web_sys::console::warn_1;
use crate::node::{RespoComponent, RespoEffectType, RespoEvent, RespoEventMark, RespoEventMarkFn, RespoNode};

use super::renderer::load_coord_target_tree;
use super::util;
use crate::node::dom_change::{ChildDomOp, DomChange, RespoCoord};

use crate::app::renderer::build_dom_tree;
Expand Down Expand Up @@ -386,11 +387,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e
.run(RespoEventMark::new("change", &coord, wrap_event))
.expect("handle change event");
}) as Box<dyn FnMut(InputEvent)>);
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onchange(Some(handler.as_ref().unchecked_ref()));
handler.forget();
match element.tag_name().as_str() {
"INPUT" => {
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onchange(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
"TEXTAREA" => {
element
.dyn_ref::<HtmlTextAreaElement>()
.expect("convert to html input element")
.set_onchange(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
_ => {
util::warn_log!("not handled change event for element: {}", element.tag_name());
}
}
}
"keydown" => {
let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| {
Expand All @@ -409,11 +424,26 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e
.run(RespoEventMark::new("keydown", &coord, wrap_event))
.expect("handle keydown event");
}) as Box<dyn FnMut(KeyboardEvent)>);
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeydown(Some(handler.as_ref().unchecked_ref()));
handler.forget();

match element.tag_name().as_str() {
"INPUT" => {
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeydown(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
"TEXTAREA" => {
element
.dyn_ref::<HtmlTextAreaElement>()
.expect("convert to html input element")
.set_onkeydown(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
_ => {
util::warn_log!("not handled keydown event for element: {}", element.tag_name());
}
}
}
"keyup" => {
let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| {
Expand All @@ -431,11 +461,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e
.run(RespoEventMark::new("keyup", &coord, wrap_event))
.expect("handle keyup event");
}) as Box<dyn FnMut(KeyboardEvent)>);
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeyup(Some(handler.as_ref().unchecked_ref()));
handler.forget();
match element.tag_name().as_str() {
"INPUT" => {
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeyup(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
"TEXTAREA" => {
element
.dyn_ref::<HtmlTextAreaElement>()
.expect("convert to html input element")
.set_onkeyup(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
_ => {
util::warn_log!("not handled keyup event for element: {}", element.tag_name());
}
}
}
"keypress" => {
let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| {
Expand All @@ -453,11 +497,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e
.run(RespoEventMark::new("keypress", &coord, wrap_event))
.expect("handle keypress event");
}) as Box<dyn FnMut(KeyboardEvent)>);
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeypress(Some(handler.as_ref().unchecked_ref()));
handler.forget();
match element.tag_name().as_str() {
"INPUT" => {
element
.dyn_ref::<HtmlInputElement>()
.expect("convert to html input element")
.set_onkeypress(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
"TEXTAREA" => {
element
.dyn_ref::<HtmlTextAreaElement>()
.expect("convert to html input element")
.set_onkeypress(Some(handler.as_ref().unchecked_ref()));
handler.forget();
}
_ => {
util::warn_log!("not handled keypress event for element: {}", element.tag_name());
}
}
}
"focus" => {
let handler = Closure::wrap(Box::new(move |e: FocusEvent| {
Expand Down

0 comments on commit 7880f6b

Please sign in to comment.