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

Make signal callable on stable #1550

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

ealmloff
Copy link
Member

(Thanks to @matthunz for letting me know about dtolnay's amazing article about derefing to closures on stable!)

This restores the previously unsound implementation of Deref<Target = dyn Fn() -> Ref<'static, T>> on signals which lets you call the signal like a function instead of reading the signal:

fn App(cx: Scope) -> Element {
    let signal = Signal::new("hello world".to_string());
    // You can call signals like functions to get a Ref of their value.
    assert_eq!(&*signal(), "hello world");

    render! {
        "hello world"
    }
}

@ealmloff ealmloff added enhancement New feature or request signals Related to the signals crate labels Oct 16, 2023
@jkelleyrtp
Copy link
Member

jkelleyrtp commented Oct 17, 2023

What's cool about this is you can now do very simple iters:

for todo in todos().iter() { 
    div { "{todo.title}" }
}

Looks good

@jkelleyrtp jkelleyrtp merged commit 025a321 into DioxusLabs:master Oct 17, 2023
10 checks passed
@ealmloff ealmloff deleted the restore-deref-fn-signal branch October 17, 2023 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request signals Related to the signals crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants