Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot create optional callback #1041

Closed
dancespiele opened this issue Mar 18, 2020 · 2 comments
Closed

I cannot create optional callback #1041

dancespiele opened this issue Mar 18, 2020 · 2 comments
Labels

Comments

@dancespiele
Copy link
Contributor

dancespiele commented Mar 18, 2020

Question

I have a component which I want to include a optional callback.
I have this in Props

#[derive(Clone, Properties)]
pub struct Props {
    #[prop_or_default]
    pub class_name: String,
    #[prop_or(DefaultCallback {
        callback: Callback::noop()
    })]
    pub onsignal: DefaultCallback<Callback<()>>,
    pub children: Children,
}

now when I call that component and include a callback in the attribute onsignal:

<NavbarItem
  onsignal=self.link.callback(move |_| Msg::TroggleMenu)>
  <Assets
   asset=Icon::Menu
   class_name="navbar-menu"
  />
</NavbarItem>

I get this error:

the trait bound `yew::virtual_dom::vcomp::VComp: yew::virtual_dom::Transformer<yew::callback::Callback<_>, utils::DefaultCallback<yew::callback::Callback<()>>>` is not satisfied
the trait `yew::virtual_dom::Transformer<yew::callback::Callback<_>, utils::DefaultCallback<yew::callback::Callback<()>>>` is not implemented for `yew::virtual_dom::vcomp::VComp`
help: the following implementations were found:
        <yew::virtual_dom::vcomp::VComp as yew::virtual_dom::Transformer<&'a T, T>>
        <yew::virtual_dom::vcomp::VComp as yew::virtual_dom::Transformer<&'a T, std::option::Option<T>>>
        <yew::virtual_dom::vcomp::VComp as yew::virtual_dom::Transformer<&'a str, std::option::Option<std::string::String>>>
        <yew::virtual_dom::vcomp::VComp as yew::virtual_dom::Transformer<&'a str, std::string::String>>
      and 3 others
note: required by `yew::virtual_dom::Transformer::transform`rustc(E0277)
navbar.rs(116, 42): the trait `yew::virtual_dom::Transformer<yew::callback::Callback<_>, utils::DefaultCallback<yew::callback::Callback<()>>>` is not implemented for `yew::

this the navbar component code:

https://github.com/spielrs/yew-styles-page/tree/add-default-callback-navbar-item/crate/yew_styles/src/components/navbar

What I've tried (optional)

implement Transformer for DefaultCallback<Callback<()>> but didn't work

@dancespiele
Copy link
Contributor Author

dancespiele commented Mar 18, 2020

I have discoverd that with this resolve my problem:

#[prop_or(Callback::noop())]
    pub onsignal: Callback<()>,

but with your PR will make this more intuitive

@jstarry
Copy link
Member

jstarry commented Mar 20, 2020

Cool, I'm going to close this "question" issue then. The PR can still move forward though!

@jstarry jstarry closed this as completed Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants