HapticX / happyx

Macro-oriented asynchronous web-framework written in Nim with ♥
https://hapticx.github.io/happyx/
MIT License
512 stars 17 forks source link

standard syntax for 'anonymous' components 🔥 #184

Closed quimt closed 9 months ago

quimt commented 9 months ago

Sometimes we just want to create something like a component on the fly, without worrying about its name or derived type beyond that. Karax has a buildHtml that returns VNodes, since everything is a VNode and components are explicitly declared to render to VNodes.

In happyX, tagRefs are pretty low-level concepts, and most developers will probably just want to deal with the Component type., for simplicity's sake. So it seems like anonymous fragments of code in the DSL should be of type Component, which can be set up by taking advantage of the slot mechanism.

component Container:
  `template`:
    slot

This works fine, but an annoying thing for developers is that the name of such an anonymous component must be set and implemented by each development team. Really it feels like the framework should decide on a standard name for such a basic concept. It also seems like the framework should have a final say on how this is implemented, since some additional work with the macros might give a keyword that wouldn't need other hints like 'use' and 'component' to be used along with it.

Ethosa commented 9 months ago

Since next commit you can use buildHtml for this:

appRoutes("app"):
  "/issue184":
    var x = buildHtml(tDiv):
      "Hello?"
    buildHtml:
      x
      x
      x:
        "world!"

image