sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

Make `Option<T>` prop fields optional by default #531

Closed danielalvsaaker closed 1 year ago

danielalvsaaker commented 1 year ago

Optional fields by default, opt-out by setting #[prop(!optional)].

Example:

#[derive(Props)]
struct Props {
    #[prop(!optional, setter(strip_option))]
    required: Option<()>,
    optional: Option<()>,
}

// Compiles
Props::builder()
    .required(())
    .build();

Closes #483.

codecov[bot] commented 1 year ago

Codecov Report

Base: 64.96% // Head: 63.21% // Decreases project coverage by -1.75% :warning:

Coverage data is based on head (6321c9c) compared to base (3057f67). Patch coverage: 82.35% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #531 +/- ## ========================================== - Coverage 64.96% 63.21% -1.76% ========================================== Files 53 54 +1 Lines 8515 8965 +450 ========================================== + Hits 5532 5667 +135 - Misses 2983 3298 +315 ``` | [Impacted Files](https://codecov.io/gh/sycamore-rs/sycamore/pull/531?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs) | Coverage Δ | | |---|---|---| | [packages/sycamore-macro/src/props.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUtbWFjcm8vc3JjL3Byb3BzLnJz) | `72.60% <82.35%> (+0.39%)` | :arrow_up: | | [packages/sycamore/src/utils.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUvc3JjL3V0aWxzLnJz) | `0.00% <0.00%> (-33.34%)` | :arrow_down: | | [packages/sycamore-core/src/generic\_node.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUtY29yZS9zcmMvZ2VuZXJpY19ub2RlLnJz) | `75.44% <0.00%> (-24.56%)` | :arrow_down: | | [packages/sycamore-macro/src/view/codegen.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUtbWFjcm8vc3JjL3ZpZXcvY29kZWdlbi5ycw==) | `95.58% <0.00%> (-1.88%)` | :arrow_down: | | [packages/sycamore-macro/src/view/mod.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUtbWFjcm8vc3JjL3ZpZXcvbW9kLnJz) | `61.70% <0.00%> (-1.35%)` | :arrow_down: | | [packages/sycamore/src/web/mod.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUvc3JjL3dlYi9tb2QucnM=) | `87.67% <0.00%> (-0.65%)` | :arrow_down: | | [packages/sycamore-core/src/render.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUtY29yZS9zcmMvcmVuZGVyLnJz) | `58.33% <0.00%> (-0.63%)` | :arrow_down: | | [packages/sycamore/src/suspense.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-cGFja2FnZXMvc3ljYW1vcmUvc3JjL3N1c3BlbnNlLnJz) | `94.48% <0.00%> (-0.09%)` | :arrow_down: | | [website/src/index.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-d2Vic2l0ZS9zcmMvaW5kZXgucnM=) | `0.00% <0.00%> (ø)` | | | [website/src/sidebar.rs](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs#diff-d2Vic2l0ZS9zcmMvc2lkZWJhci5ycw==) | `0.00% <0.00%> (ø)` | | | ... and [15 more](https://codecov.io/gh/sycamore-rs/sycamore/pull/531/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sycamore-rs)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

lukechu10 commented 1 year ago

I would like to get this merged so if you don't mind, I'll just add the test myself to not delay this longer.