Skip to content

Commit 849b37d

Browse files
author
mc1098
committed
Fix __macro_new to use IntoEventCallback
1 parent 9b2362f commit 849b37d

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
@@ -116,12 +116,13 @@ pub trait StaticEvent {
116116
}
117117

118118
use crate::callback::Callback;
119-
use crate::html::IntoPropValue;
120119
use crate::virtual_dom::Listener;
121120
use gloo::events::{EventListener, EventListenerOptions};
122121
use std::rc::Rc;
123122
use web_sys::{Element, EventTarget};
124123

124+
use super::IntoEventCallback;
125+
125126
/// A wrapper for a callback which attaches event listeners to elements.
126127
#[derive(Clone, Debug)]
127128
pub struct Wrapper<T: StaticEvent> {
@@ -136,10 +137,8 @@ impl<T: StaticEvent + 'static> Wrapper<T> {
136137

137138
#[doc(hidden)]
138139
#[inline]
139-
pub fn __macro_new(
140-
callback: impl IntoPropValue<Option<Callback<T::Event>>>,
141-
) -> Option<Rc<dyn Listener>> {
142-
let callback = callback.into_prop_value()?;
140+
pub fn __macro_new(callback: impl IntoEventCallback<T::Event>) -> Option<Rc<dyn Listener>> {
141+
let callback = callback.into_event_callback()?;
143142
Some(Rc::new(Self::new(callback)))
144143
}
145144
}

0 commit comments

Comments
 (0)