Expand description
Interactivity for handling JS events.
WSDOM is one-way, so JS code cannot directly call Rust code. Instead, we adopt a mechanism based on async.
The new_callback function returns a Rust Stream s
and
a JavaScript object f
that can be called (i.e. a function/closure).
Each time f
is called like f(arg)
,
the Rust stream will yield the arg
object.
async fn example(browser: &Browser, button: wsdom::dom::HTMLButtonElement) {
let (mut stream, func) = wsdom::callback::new_callback::<wsdom::dom::MouseEvent>(&browser);
button.add_event_listener(&"click", &func, &wsdom::undefined());
use futures_util::StreamExt;
let _click_event: Option<wsdom::dom::MouseEvent> = stream.next().await;
println!("the button was clicked!");
}
Structs§
- Callback
- Listens for JavaScript callbacks.
Functions§
- new_
callback - Create a new Callback and a corresponding JavaScript function.