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

Breaking change: add support for required props #525

Merged
merged 9 commits into from
Jul 24, 2019

Conversation

jstarry
Copy link
Member

@jstarry jstarry commented Jul 13, 2019

Problem

Before this change, properties must implement default which means that even if a prop always gets passed in by value to a component, it still needs a default state in props. No longer!

Solution

This breaking change allows annotating prop fields as required by using a procedural derive macro.

Notes

  • If a prop is required, it does not need to implement Default.
  • If a prop is optional (not required), it must now implement Default.
  • If a required prop is not passed into a component, your app will not compile.
  • Props with lifetime parameters are not supported
  • Props with generics are supported!

Breaking changes:

  1. Properties must now implement the Properties trait by adding #[derive(Properties)] to their prop structs
  2. Non-required prop fields must implement Default
  3. Callback props created through the closure syntax will no longer return an Option type

Depends on #518

Copy link

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about Yew but I had a quick skim through the macro implementation. Looks nicely written!

crates/props-derive/src/lib.rs Outdated Show resolved Hide resolved
crates/props-derive/src/lib.rs Outdated Show resolved Hide resolved
crates/props-derive/src/lib.rs Outdated Show resolved Hide resolved
@jstarry jstarry force-pushed the required-props branch 3 times, most recently from 7ecf705 to 5c6cbd4 Compare July 20, 2019 15:27
@therustmonk
Copy link
Member

I cry of happiness. It's amazing!!!

@jstarry
Copy link
Member Author

jstarry commented Jul 23, 2019

bors r+

bors bot added a commit that referenced this pull request Jul 23, 2019
525: Breaking change: add support for required props r=jstarry a=jstarry

#### Problem
Before this change, properties must implement default which means that even if a prop always gets passed in by value to a component, it still needs a default state in props. No longer!

#### Solution
This breaking change allows annotating prop fields as required by using a procedural derive macro.

#### Notes
- If a prop is required, it does not need to implement `Default`.
- If a prop is optional (not required), it must now implement `Default`.
- If a required prop is not passed into a component, your app will not compile.
- Props with lifetime parameters are not supported
- Props with generics are supported!

#### Breaking changes:
1. Properties must now implement the `Properties` trait by adding `#[derive(Properties)]` to their prop structs
2. Non-required prop fields must implement `Default`
3. Callback props created through the closure syntax will no longer return an `Option` type

Depends on #518

Co-authored-by: Justin Starry <jstarry@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Jul 23, 2019

Build failed

@jstarry
Copy link
Member Author

jstarry commented Jul 24, 2019

bors r+

bors bot added a commit that referenced this pull request Jul 24, 2019
525: Breaking change: add support for required props r=jstarry a=jstarry

#### Problem
Before this change, properties must implement default which means that even if a prop always gets passed in by value to a component, it still needs a default state in props. No longer!

#### Solution
This breaking change allows annotating prop fields as required by using a procedural derive macro.

#### Notes
- If a prop is required, it does not need to implement `Default`.
- If a prop is optional (not required), it must now implement `Default`.
- If a required prop is not passed into a component, your app will not compile.
- Props with lifetime parameters are not supported
- Props with generics are supported!

#### Breaking changes:
1. Properties must now implement the `Properties` trait by adding `#[derive(Properties)]` to their prop structs
2. Non-required prop fields must implement `Default`
3. Callback props created through the closure syntax will no longer return an `Option` type

Depends on #518

Co-authored-by: Justin Starry <jstarry@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Jul 24, 2019

Build succeeded

@bors bors bot merged commit 9781884 into yewstack:master Jul 24, 2019
@jstarry jstarry deleted the required-props branch April 4, 2020 06:14
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.

3 participants