Skip to content

Commit 8ed4aad

Browse files
author
mc1098
committed
Fix __macro_new to use IntoEventCallback
1 parent 3beda70 commit 8ed4aad

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

packages/yew-macro/tests/html_macro/element-fail.stderr

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,38 +302,38 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<Cow<'stat
302302
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
303303
= note: required by `into_prop_value`
304304

305-
error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
305+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `{integer}`
306306
--> $DIR/element-fail.rs:51:29
307307
|
308308
51 | html! { <input on:click=1 /> };
309-
| ^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `{integer}`
309+
| ^ expected an `Fn<(MouseEvent,)>` closure, found `{integer}`
310310
|
311-
= help: the following implementations were found:
312-
<&'static str as IntoPropValue<Cow<'static, str>>>
313-
<&'static str as IntoPropValue<Option<Cow<'static, str>>>>
314-
<&'static str as IntoPropValue<Option<String>>>
315-
<&'static str as IntoPropValue<String>>
316-
and 11 others
311+
= help: the trait `Fn<(MouseEvent,)>` is not implemented for `{integer}`
312+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `{integer}`
317313
= note: required by `Wrapper::<T>::__macro_new`
318314

319-
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
315+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `yew::Callback<String>`
320316
--> $DIR/element-fail.rs:52:30
321317
|
322318
52 | html! { <input on:click={Callback::from(|a: String| ())} /> };
323-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
319+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
320+
| |
321+
| expected an implementor of trait `IntoEventCallback<MouseEvent>`
322+
| help: consider borrowing here: `&Callback::from(|a: String| ())`
324323
|
324+
= note: the trait bound `yew::Callback<String>: IntoEventCallback<MouseEvent>` is not satisfied
325+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `yew::Callback<String>`
325326
= note: required by `Wrapper::<T>::__macro_new`
326327

327-
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not satisfied
328+
error[E0277]: the trait bound `Option<{integer}>: IntoEventCallback<FocusEvent>` is not satisfied
328329
--> $DIR/element-fail.rs:53:30
329330
|
330331
53 | html! { <input on:focus={Some(5)} /> };
331-
| ^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not implemented for `Option<{integer}>`
332+
| ^^^^^^^ the trait `IntoEventCallback<FocusEvent>` is not implemented for `Option<{integer}>`
332333
|
333334
= help: the following implementations were found:
334-
<Option<&'static str> as IntoPropValue<Option<Cow<'static, str>>>>
335-
<Option<&'static str> as IntoPropValue<Option<String>>>
336-
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
335+
<Option<T> as IntoEventCallback<EVENT>>
336+
<Option<yew::Callback<EVENT>> as IntoEventCallback<EVENT>>
337337
= note: required by `Wrapper::<T>::__macro_new`
338338

339339
error[E0277]: the trait bound `(): IntoPropValue<yew::NodeRef>` is not satisfied
@@ -356,12 +356,17 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
356356
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
357357
= note: required by `into_prop_value`
358358

359-
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
359+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `yew::Callback<String>`
360360
--> $DIR/element-fail.rs:58:30
361361
|
362362
58 | html! { <input on:click={Callback::from(|a: String| ())} /> };
363-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
363+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
364+
| |
365+
| expected an implementor of trait `IntoEventCallback<MouseEvent>`
366+
| help: consider borrowing here: `&Callback::from(|a: String| ())`
364367
|
368+
= note: the trait bound `yew::Callback<String>: IntoEventCallback<MouseEvent>` is not satisfied
369+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `yew::Callback<String>`
365370
= note: required by `Wrapper::<T>::__macro_new`
366371

367372
error[E0277]: the trait bound `NotToString: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied

packages/yew/src/html/listener/events.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ pub trait StaticEvent {
120120
}
121121

122122
use crate::callback::Callback;
123-
use crate::html::IntoPropValue;
124123
use crate::virtual_dom::Listener;
125124
use gloo::events::{EventListener, EventListenerOptions};
126125
use std::rc::Rc;
127126
use web_sys::{Element, EventTarget};
128127

128+
use super::IntoEventCallback;
129+
129130
/// A wrapper for a callback which attaches event listeners to elements.
130131
#[derive(Clone, Debug)]
131132
pub struct Wrapper<T: StaticEvent> {
@@ -140,10 +141,8 @@ impl<T: StaticEvent + 'static> Wrapper<T> {
140141

141142
#[doc(hidden)]
142143
#[inline]
143-
pub fn __macro_new(
144-
callback: impl IntoPropValue<Option<Callback<T::Event>>>,
145-
) -> Option<Rc<dyn Listener>> {
146-
let callback = callback.into_prop_value()?;
144+
pub fn __macro_new(callback: impl IntoEventCallback<T::Event>) -> Option<Rc<dyn Listener>> {
145+
let callback = callback.into_event_callback()?;
147146
Some(Rc::new(Self::new(callback)))
148147
}
149148
}

0 commit comments

Comments
 (0)