DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.3k stars 779 forks source link

rsx! macro should allow let statements #2593

Closed uzytkownik closed 1 month ago

uzytkownik commented 2 months ago

Feature Request

Due to nature of Rust lifetimes there are places where let x = foo.y() are useful. For example recently in my code:

    rsx! {
        div {
            {
                let x = signal.read(); // signal is not Signal<Vec<_>> but Signal<Rc<Vec<_>>>
                rsx! {
                    for y in x {
                        // ...
                    }
                }
            }
        }
    }

It leaves two options:

It would be nice if this can be changed to:

    rsx! {
        div {
            let x = signal.read(); 
            for y in x {
                /// ...
            }
        }
    }

Implement Suggestion

B...
let x = y;
A...

can be lowered to:

B...
{
    let x = y;
    rsx! {
        A...
    }
}
jkelleyrtp commented 1 month ago

The fact that order matters here means we probably won't support this since it's not compatible with our hotreloading engine.

The snippet you posted does compile though I imagine there are snippets that don't, and in those cases, we should be better at extending lifetimes.

This might be a desugaring issue with for and if statements.

If you have a specific snippet that's not working, please make an issue and we can try and get that fixed!