Switch Closure::new to wrap in paint example

Show off stable usage!
This commit is contained in:
Alex Crichton 2018-10-03 09:53:55 -07:00
parent 4a5e13b08b
commit 991e61931e
2 changed files with 7 additions and 7 deletions

View File

@ -8,7 +8,7 @@ crate-type = ["cdylib"]
[dependencies]
js-sys = { path = "../../crates/js-sys" }
wasm-bindgen = { path = "../..", features = ["nightly"] }
wasm-bindgen = { path = "../.." }
[dependencies.web-sys]
path = "../../crates/web-sys"

View File

@ -36,11 +36,11 @@ pub fn main() {
{
let context = context.clone();
let pressed = pressed.clone();
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
context.begin_path();
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
pressed.set(true);
});
}) as Box<FnMut(_)>);
(canvas.as_ref() as &web_sys::EventTarget)
.add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())
.unwrap();
@ -49,14 +49,14 @@ pub fn main() {
{
let context = context.clone();
let pressed = pressed.clone();
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
if pressed.get() {
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
context.stroke();
context.begin_path();
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
}
});
}) as Box<FnMut(_)>);
(canvas.as_ref() as &web_sys::EventTarget)
.add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref())
.unwrap();
@ -65,11 +65,11 @@ pub fn main() {
{
let context = context.clone();
let pressed = pressed.clone();
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
pressed.set(false);
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
context.stroke();
});
}) as Box<FnMut(_)>);
(canvas.as_ref() as &web_sys::EventTarget)
.add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())
.unwrap();