mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
Merge pull request #924 from alexcrichton/no-closure-new
Switch `Closure::new` to `wrap` in paint example
This commit is contained in:
commit
b7f1f9c086
@ -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"
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user