8000 allow `_signal` functions to take `Option` · Issue #186 · MoonZoon/MoonZoon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

allow _signal functions to take Option #186

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

Open
databasedav opened this issue Sep 28, 2023 · 4 comments
Open

allow _signal functions to take Option #186

databasedav opened this issue Sep 28, 2023 · 4 comments

Comments

@databasedav
Copy link
Contributor
databasedav commented Sep 28, 2023

it's super convenient that functions like .item/.layer etc. take IntoOptionElement because it enables deciding emptiness inline e.g.

Column::new().item(if condition { Some(...) } else { None })

but the _signal functions (including those for styles) don't allow such a pattern so one must do either

Column::new().item_signal(
    if let Some(data) = data_option {
        data.signal(|data| El::new().child(...)).map(Some).left_either()
    } else {
        always(None).right_either()
    }
)

or

let mut el = Column::new();
if let Some(data) = data_option {
    el = el.item_signal(data.signal().map(...))
}
el

which are far less ergonomic, instead i should be able to simply do

Column::new().item_signal(data_option.map(|data| data.signal().map(|data| El::new().child(...))))
@databasedav databasedav changed the title allow _signal functions to take None allow _signal functions to take Option Sep 28, 2023
@NeverGivinUp
Copy link
Contributor

Wouldn't you have to request such a signature change from the future_signals crate?

@databasedav
Copy link
Contributor Author
databasedav commented Sep 28, 2023

@NeverGivinUp no it should be managed at the Zoon level

@MartinKavik
Copy link
Member

It isn't allowed because I almost don't need it in my code and mainly because it makes the types too complex for both compiler and human. So I didn't want to introduce some dummy structs or helper functions or traits to make it work.

But I've created an example in this repo to demostrate potential problems and we can use it to try to design better API to resolve the issue.

The example: https://github.com/MoonZoon/MoonZoon/blob/main/examples/signal_params/frontend/src/main.rs

@databasedav
Copy link
Contributor Author
databasedav commented Feb 10, 2024

Silkenweb has an interesting approach to this RefSignalOrValue though i'm not sure if it

makes the types too complex for both compiler and human

edit: nvm, RefSignalOrValue has nothing to do with options 😭

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

No branches or pull requests

3 participants
0