Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Commit

Permalink
Make code example show
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hobden committed May 10, 2017
1 parent 04827ad commit 7fbdd52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion presentation/chapters/en-US/wasm.chapter
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ Calling the Javascript function:

## DOM Interaction

There is a [WebPlatform crate](https://github.com/tcr/rust-webplatform) to explore and contribute to. Working with it looks like this:
There is a [WebPlatform crate](https://github.com/tcr/rust-webplatform) to explore and contribute to.

<pre><code data-source="chapters/shared/code/wasm/19.rs" data-trim="hljs rust"></code></pre>

---

Expand Down
24 changes: 24 additions & 0 deletions presentation/chapters/shared/code/wasm/19.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern crate webplatform;

fn main() {
let document = webplatform::init();
let body = document.element_query("body")
.unwrap();
body.html_append("\
<h1>This header brought to you by Rust</h1>\
<button>Click me!</button>\
");

let button = document.element_query("button")
.unwrap();
button.on("mouseenter", move |_| {
println!("Mouse entered!");
body.html_append("<p>Mouse entered!</p>");
});
button.on("click", |_| {
println!("Clicked!");
webplatform::alert("Clicked!");
});

webplatform::spin();
}

0 comments on commit 7fbdd52

Please sign in to comment.