Pauan / rust-dominator

Zero-cost ultra-high-performance declarative DOM library using FRP signals for Rust!
MIT License
998 stars 63 forks source link

feat: introduce support for `HtmlSelectElement` and `Change.value` #76

Closed EstebanBorai closed 1 year ago

EstebanBorai commented 1 year ago

Introduces support to retrieve the value from HTMLInputElements which value is String compatible and HTMLSelectElement in order to retrieve selected option values.

Pauan commented 1 year ago

Thanks, but this is already possible:

html!("select" => HtmlSelectElement, {
    .with_node!(element => {
        .event(move |_: events::Change| {
            let value = element.value();
            // ...
        })
    })
})

You can access any of the methods on the underlying DOM type by using with_node!

EstebanBorai commented 1 year ago

Thanks, but this is already possible:

html!("select" => HtmlSelectElement, {
    .with_node!(element => {
        .event(move |_: events::Change| {
            let value = element.value();
            // ...
        })
    })
})

You can access any of the methods on the underlying DOM type by using with_node!

Hi @Pauan thanks for the quick prompt!

Yeah! In my use case I'm exposing the Change struct which impl I'm extending. But I found a way around it.

If you consider this PR is not necessary I could close it.

Thanks!

Pauan commented 1 year ago

Yeah! In my use case I'm exposing the Change struct which impl I'm extending.

Why are you doing that?

EstebanBorai commented 1 year ago

Yeah! In my use case I'm exposing the Change struct which impl I'm extending.

Why are you doing that?

In my codebase I have a handler on the change event which takes the event and creates an instance of this Change struct we are talking about.

Pauan commented 1 year ago

Okay, but I'm still not sure why you're doing that. What are you trying to accomplish?

EstebanBorai commented 1 year ago

Okay, but I'm still not sure why you're doing that. What are you trying to accomplish?

Access the element value based on the previous premise.

Given that I only have access for such Change struct addressed in the PR, I wanted to expose the value attribute value by adding the method introduced here.

Pauan commented 1 year ago

But why are you creating a new Change struct at all? Why not just pass in the value directly?

html!("select" => HtmlSelectElement, {
    .with_node!(element => {
        .event(move |_: events::Change| {
            state.some_method(element.value());
        })
    })
})
EstebanBorai commented 1 year ago

But why are you creating a new Change struct at all? Why not just pass in the value directly?

html!("select" => HtmlSelectElement, {
    .with_node!(element => {
        .event(move |_: events::Change| {
            state.some_method(element.value());
        })
    })
})

Hi @Pauan, I'm not the author of the crate so I'm not sure why the API is implemented like this. I will close this PR as theres clearly a solution already for what I purpose here.

Thanks for your time an patience and of course for such a great crate!

Pauan commented 1 year ago

Oh, interesting, I'm curious which crate you are using. Is it MoonZoon? I think they have a different way of accessing DOM nodes.