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

Support passing a struct instance as properties #271

Merged
merged 1 commit into from
Jun 7, 2018
Merged

Support passing a struct instance as properties #271

merged 1 commit into from
Jun 7, 2018

Conversation

limira
Copy link
Contributor

@limira limira commented Jun 7, 2018

If we have

#[derive(Debug, Default, Eq, PartialEq)]
pub struct MyProps {
    val: i32,
}

impl Component<Context> for MyComp {
    type Message = Msg;
    type Properties = MyProps;
}

then if we have an instance of MyProps, we can pass it directly to its Component:

let my_props = MyProps {val: 64 };
html! {
    <MyComp: props=my_props, />
}

Is there a better syntax for this?
If this is merged as is, any struct that is used for a Component's properties will not allowed to contain a field named props!

Edit: I you merge this, please squash all commits. While working on this, I got stuck by an error I don't know how to solve, just commit to get back to the original working code (from master).

@therustmonk
Copy link
Member

Hi! @limira Thank you for the PR and the idea 👍
I made it easier and avoid using potential property's name.
Also I squashed it and add some tests. It's ready for merging! 🎉

@therustmonk
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Jun 7, 2018
271: Support passing a struct instance as properties r=DenisKolodin a=limira

If we have
```rust
#[derive(Debug, Default, Eq, PartialEq)]
pub struct MyProps {
    val: i32,
}

impl Component<Context> for MyComp {
    type Message = Msg;
    type Properties = MyProps;
}
```
then if we have an instance of `MyProps`, we can pass it directly to its Component:
```rust
let my_props = MyProps {val: 64 };
html! {
    <MyComp: props=my_props, />
}
```
Is there a better syntax for this?
If this is merged as is, any `struct` that is used for a Component's properties will not allowed to contain a field named `props`!

Edit: I you merge this, please squash all commits. While working on this, I got stuck by an error I don't know how to solve, just commit to get back to the original working code (from master).

Co-authored-by: Limira <20672976+limira@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Jun 7, 2018

Build succeeded

@bors bors bot merged commit e22b0ec into yewstack:master Jun 7, 2018
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