lustre-labs / lustre

An Elm-inspired framework for building HTML templates, single page applications, and server-rendered components in Gleam!
https://hexdocs.pm/lustre
MIT License
744 stars 53 forks source link

✨ Implement a `fragment` to contain multiple elements at once #16

Closed hayleigh-dot-dev closed 2 months ago

hayleigh-dot-dev commented 8 months ago

In other frameworks it's often quite handy to be able to return multiple elements without wrapping them in some single container. Lustre should support this too! We should define a new variant of the Element type...

  pub opaque type Element(msg) {
    ...
+   Fragment(List(Element(msg))
    ...
  }

... as well as exposing a new constructor for it.

pub fn fragment(children: List(Element(msg)) -> Element(msg) {
  Fragment(children)
}

Then the render methods to_string and to_string_builder as well as the runtime need to be updated to support this new element type.

giacomocavalieri commented 8 months ago

If this is still up for grabs, I'd love to try implementing it!

JScearcy commented 3 months ago

Cool package! Curious if help is still wanted on this? I think there was some drift in the current implementation vs what's there today but I think I have enough understanding to put this together

hayleigh-dot-dev commented 3 months ago

If you think you could work it out I'd be very grateful! It has so-far eluded me, I'd appreciate someone that knows what they're doing chiming in 😅

JScearcy commented 3 months ago

Awesome, thanks! I'll post an initial approach this afternoon for consideration

JScearcy commented 3 months ago

I posted an initial draft PR, if anyone has feedback or suggestions I'm happy to update, after an initial round I can work on a more complete integration. Initially I just focused on the client runtime

Edit: Gonna resolve the conflicts , still open for feedback in the mean time but def gotta weave things together

hayleigh-dot-dev commented 3 months ago

If you're on discord feel free to drop me a DM @hayleigh.dev ^.^