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

Disambiguate if expressions in rsx by requiring curlies, allow shorthand component/element initialization #1810

Merged
merged 11 commits into from Jan 11, 2024

Conversation

jkelleyrtp
Copy link
Member

@jkelleyrtp jkelleyrtp commented Jan 11, 2024

This PR changes how rsx interprets expressions, requiring them to be wrapped in curly braces.

This is a hugely breaking PR but allows a number of goodies like letting us keep consistency of if/for special cases and shorthand struct initialization.

It could also lead the way to improved autocomplete via partial expansion, however this is not yet implemented.

In it's current form it provides way better autocomplete when working inside curly braces and better autocomplete of attributes and props.

So, this works now:

if cond {
    div {}
} else {
   h1 {}
}

And so does this:

let a = 123;
let b = 456;
let c = 789;
let children = render!{ "hi" };

rsx! {
    Component { a, b, c, children }
}

This also supports elements:

let class = "123";

rsx! {
    div { class } 
}

However we don't special-case children and currently panic if an attribute named "children" is present.

In theory we could accept the children argument in elements, but I just didn't get around to it here.

@jkelleyrtp jkelleyrtp added breaking This is a breaking change syntax labels Jan 11, 2024
@jkelleyrtp jkelleyrtp changed the title Disambiguate if expressions in rsx by requiring curlies, allow shorthand struct initialization Disambiguate if expressions in rsx by requiring curlies, allow shorthand component/element initialization Jan 11, 2024
@jkelleyrtp jkelleyrtp marked this pull request as ready for review January 11, 2024 06:46
// ```
// match {
// val => div {}
// other_val => div {}
Copy link
Member

@ealmloff ealmloff Jan 11, 2024

Choose a reason for hiding this comment

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

I think allowing you to do normal rsx elements in match arms would be more consistant with if statements and loops in the future, but it could be in a different PR

Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

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

Looks good! Excited for better autocomplete

@jkelleyrtp jkelleyrtp merged commit f7bf156 into master Jan 11, 2024
10 checks passed
@jkelleyrtp jkelleyrtp deleted the jk/disambiguate-exprs-in-rsx branch January 11, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a breaking change syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants