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

Destructuring let (0.7) #2655

Merged
merged 2 commits into from
Jun 29, 2024
Merged

Destructuring let (0.7) #2655

merged 2 commits into from
Jun 29, 2024

Conversation

Jinxit
Copy link
Contributor

@Jinxit Jinxit commented Jun 29, 2024

This PR adds a new let() syntax to components, while also keeping let: alive for backwards compatibility.

Example usage:

view! {
    <For
        each=move || data.get()
        key=|n| *n
        // stores the item in each row in a variable named `data`
        let(data)
    >
        <p>{data}</p>
    </For>
}

This also allows for destructuring of tuples and structs, as it's just directly embedded in the children function's arguments.

view! {
    <For
        each=move || data.get()
        key=|n| *n
        // stores the item in each row in a variable named `data`
        let((tup1, tup2)) // note the extra parentheses for destructuring
    >
        <p>{tup1} {tup2}</p>
    </For>
}

I haven't gone through all the examples and changed the usage as I wasn't sure what you wanted to present as the default. Would you like me to do that?

This lets users use destructuring when binding more complex values, and we also get better IDE support.
@benwis
Copy link
Contributor

benwis commented Jun 29, 2024

Lovely, thanks for the PR

@benwis benwis merged commit a9e506d into leptos-rs:leptos_0.7 Jun 29, 2024
@Jinxit Jinxit deleted the let_0.7 branch June 29, 2024 22:20
gbj pushed a commit that referenced this pull request Jul 4, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
agraboso pushed a commit to agraboso/leptos that referenced this pull request Jul 16, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
gbj pushed a commit that referenced this pull request Jul 24, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
gbj pushed a commit that referenced this pull request Jul 30, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
gbj pushed a commit that referenced this pull request Aug 1, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
gbj pushed a commit that referenced this pull request Aug 1, 2024
* Use `let()` syntax for bindings

This lets users use destructuring when binding more complex values, and we also get better IDE support.

* Update rstml
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