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

Allow implicitly cloning arguments instead of referencing #5

Merged
merged 6 commits into from
Oct 30, 2023
Merged

Allow implicitly cloning arguments instead of referencing #5

merged 6 commits into from
Oct 30, 2023

Conversation

cecton
Copy link
Member

@cecton cecton commented Oct 30, 2023

I just discovered this great library yesterday and I think it's fantastic!

Here is a new improvement for it that will allow the user to be more productive
by not having to deal with references all the time.

This PR allow the user to write types that are not references. If they are not,
the value will be cloned at the beginning of the function.

Properties in Yew should ideally be cheap-to-clone because they are passed from
parent to children by cloning. So it is safe to assume that the user will want
the actual types most of the time instead of references.

Here is an example of its usage:

use yew_autoprops::autoprops_component;
use yew::prelude::*;

#[autoprops_component]
fn CoolComponent( bool1: &bool, bool2: bool, int1: &i8, int2: i8) -> Html {
    if *bool1 {
    }

    if bool2 {
    }

    if int1 > &5 {
    }

    if int2 > 5 {
    }

    html! {
        <div>
        </div>
    }
}

@valyagolev
Copy link
Contributor

Thank you for both contributions, they seem very useful! I fixed two of the failing tests.

But this PR doesn't seem to work with generics, see the third failing test. I'll be able to look into this only a bit later – I'm completely out of context...

Since you're interested in this project, and have an eye on maybe getting it into yew, I invited you as a maintainer so you can get the CI to run automatically. It goes without saying that this comes with no expectations from you, it's purely for your own convenience if you'd ever want to contribute more.

@cecton
Copy link
Member Author

cecton commented Oct 30, 2023

But this PR doesn't seem to work with generics, see the third failing test. I'll be able to look into this only a bit later – I'm completely out of context...

no worry, its not your job to fix my bugs lol

@cecton cecton merged commit 51220ab into yewstack:master Oct 30, 2023
1 check passed
@cecton cecton deleted the allow-clones branch October 30, 2023 12:39
@valyagolev
Copy link
Contributor

Released as 0.3.0. Maybe update the README too if you have the time ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants