@@ -230,7 +230,7 @@ thread_local! {
230
230
pub struct EventListener {
231
231
target : EventTarget ,
232
232
event_type : Cow < ' static , str > ,
233
- callback : Option < Closure < FnMut ( Event ) > > ,
233
+ callback : Option < Closure < FnMut ( & Event ) > > ,
234
234
phase : EventListenerPhase ,
235
235
}
236
236
@@ -239,7 +239,7 @@ impl EventListener {
239
239
fn raw_new (
240
240
target : & EventTarget ,
241
241
event_type : Cow < ' static , str > ,
242
- callback : Closure < FnMut ( Event ) > ,
242
+ callback : Closure < FnMut ( & Event ) > ,
243
243
options : & AddEventListenerOptions ,
244
244
phase : EventListenerPhase ,
245
245
) -> Self {
@@ -283,7 +283,7 @@ impl EventListener {
283
283
/// # use gloo_events::{EventListener, EventListenerOptions};
284
284
/// # let target = unimplemented!();
285
285
/// # let event_type = "click";
286
- /// # let callback = move |e| {};
286
+ /// # fn callback(_: &web_sys::Event) {}
287
287
/// #
288
288
/// let options = EventListenerOptions::enable_prevent_default();
289
289
///
@@ -302,7 +302,7 @@ impl EventListener {
302
302
/// # use gloo_events::{EventListener, EventListenerOptions};
303
303
/// # let target = unimplemented!();
304
304
/// # let event_type = "click";
305
- /// # let callback = move |e| {};
305
+ /// # fn callback(_: &web_sys::Event) {}
306
306
/// #
307
307
/// // This runs the event listener in the capture phase, rather than the bubble phase
308
308
/// let options = EventListenerOptions::run_in_capture_phase();
@@ -322,7 +322,7 @@ impl EventListener {
322
322
/// # let target = unimplemented!();
323
323
/// #
324
324
/// let listener = EventListener::new(&target, "click", move |event| {
325
- /// let event = event.dyn_into ::<web_sys::MouseEvent>().unwrap_throw();
325
+ /// let event = event.dyn_ref ::<web_sys::MouseEvent>().unwrap_throw();
326
326
///
327
327
/// // ...
328
328
/// });
@@ -331,9 +331,9 @@ impl EventListener {
331
331
pub fn new < S , F > ( target : & EventTarget , event_type : S , callback : F ) -> Self
332
332
where
333
333
S : Into < Cow < ' static , str > > ,
334
- F : FnMut ( Event ) + ' static ,
334
+ F : FnMut ( & Event ) + ' static ,
335
335
{
336
- let callback = Closure :: wrap ( Box :: new ( callback) as Box < FnMut ( Event ) > ) ;
336
+ let callback = Closure :: wrap ( Box :: new ( callback) as Box < FnMut ( & Event ) > ) ;
337
337
338
338
NEW_OPTIONS . with ( move |options| {
339
339
Self :: raw_new (
@@ -362,7 +362,7 @@ impl EventListener {
362
362
/// # let target = unimplemented!();
363
363
/// #
364
364
/// let listener = EventListener::once(&target, "load", move |event| {
365
- /// let event = event.dyn_into ::<web_sys::ProgressEvent>().unwrap_throw();
365
+ /// let event = event.dyn_ref ::<web_sys::ProgressEvent>().unwrap_throw();
366
366
///
367
367
/// // ...
368
368
/// });
@@ -371,7 +371,7 @@ impl EventListener {
371
371
pub fn once < S , F > ( target : & EventTarget , event_type : S , callback : F ) -> Self
372
372
where
373
373
S : Into < Cow < ' static , str > > ,
374
- F : FnOnce ( Event ) + ' static ,
374
+ F : FnOnce ( & Event ) + ' static ,
375
375
{
376
376
let callback = Closure :: once ( callback) ;
377
377
@@ -450,9 +450,9 @@ impl EventListener {
450
450
) -> Self
451
451
where
452
452
S : Into < Cow < ' static , str > > ,
453
- F : FnMut ( Event ) + ' static ,
453
+ F : FnMut ( & Event ) + ' static ,
454
454
{
455
- let callback = Closure :: wrap ( Box :: new ( callback) as Box < FnMut ( Event ) > ) ;
455
+ let callback = Closure :: wrap ( Box :: new ( callback) as Box < FnMut ( & Event ) > ) ;
456
456
457
457
Self :: raw_new (
458
458
target,
@@ -514,7 +514,7 @@ impl EventListener {
514
514
) -> Self
515
515
where
516
516
S : Into < Cow < ' static , str > > ,
517
- F : FnOnce ( Event ) + ' static ,
517
+ F : FnOnce ( & Event ) + ' static ,
518
518
{
519
519
let callback = Closure :: once ( callback) ;
520
520
@@ -551,7 +551,7 @@ impl EventListener {
551
551
552
552
/// Returns the callback.
553
553
#[ inline]
554
- pub fn callback ( & self ) -> & Closure < FnMut ( Event ) > {
554
+ pub fn callback ( & self ) -> & Closure < FnMut ( & Event ) > {
555
555
// This will never panic, because `callback` is always `Some`
556
556
self . callback . as_ref ( ) . unwrap_throw ( )
557
557
}
0 commit comments