Created
October 4, 2018 14:58
-
-
Save yoshuawuyts/0e1e6e230b3f2c0d69ade5b6a5c71d0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasm_bindgen::prelude::Closure; | |
use wasm_bindgen::JsCast; | |
use web_sys::{Document, EventTarget}; | |
let document = Document::new().map_err(|_| ErrorKind::Document)?; | |
let target: EventTarget = document.into(); | |
let cb = Closure::wrap(Box::new(move || { | |
println!("hello world from WASM"); | |
}) as Box<Fn()>); | |
let event_name = "DOMContentLoaded"; | |
target | |
.add_event_listener_with_callback(event_name, cb.as_ref().unchecked_ref()) | |
.map_err(|_| ErrorKind::Document)?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use dom::{self, Document, Events}; | |
let document = Document::new()?; | |
let event = Events::DomContentLoaded; | |
document.add_event_listener(event, |_| { | |
println!("DOM Loaded!"); | |
})?; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment