Code Monkey home page Code Monkey logo

Comments (4)

gbj avatar gbj commented on May 22, 2024

To clarify: Do you mean optional props on a component or optional attributes on a DOM element?

Both should actually already be possible so if you have an example of where it's not working I'd be happy to take a look!

from leptos.

gbj avatar gbj commented on May 22, 2024

Sorry I didn't see the second half of the title when I posted this response, clearly.

Option<T> is support on attributes when T is a primitive type. It's supported on properties when T is a primitive or JsValue.

I don't support it on event listeners at the moment; note that Leptos is using global event delegation, so it's not actually adding an event listener on the element. (It does create the closure for the event listener once per instance and store it in the DOM, to be fair.)

For an event listener you'd actually need to support Fn() -> Option<Fn(web_sys::Event)> which seems a little messy to me. (Because a simple Option<Fn(web_sys::Event) isn't dynamic, since components don't re-run.)

from leptos.

jquesada2016 avatar jquesada2016 commented on May 22, 2024

I see it does in fact work! I didn't try it because I didn't see it in the docs. It wasn't until I checked the trait implementations for IntoAttribute that I saw it was implemented for many primitive types.

from leptos.

gbj avatar gbj commented on May 22, 2024

Great! I'll add something to the docs, too.

from leptos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.