Skip to content
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

Nue JS: Fragment support <></> #195

Open
goblinfactory opened this issue Feb 12, 2024 · 1 comment
Open

Nue JS: Fragment support <></> #195

goblinfactory opened this issue Feb 12, 2024 · 1 comment
Labels
low priority Done later new feature New feature or request

Comments

@goblinfactory
Copy link
Contributor

goblinfactory commented Feb 12, 2024

I might be wrong, but i think that currently the parent component that get's named, must be an HTML element.

Breaks here if you try to use a fragment;

export function getComponentName(root) {

My question is, Should Nue's reactive components support fragment elements <></> ?

Advantages

instead of

<div @name="my-dialog">
  <dialog if:="resultOK">...</dialog>
  <dialog if:="resultFail">...</dialog>
  <list if:="dialogClosed"> ... </list>
</div>

something more similar to react's empty element <></> as follows

<@name="my-dialog">
  <dialog if:="resultOK">...</dialog>
  <dialog if:="resultFail">...</dialog>
  <list if:="dialogClosed"> ... </list>
</>

Rationale

  • Be more semantic and avoid just defaulting to have a useless parent <DIV> for anchor purposes only.
  • cleaner DOM
  • Allow designers to have more semantic options for expressing intent, thus improving code cohesion.

If this isn't possible then maybe just use a div, and have an attribute ( for example render-contents-only ??) , meaning it's not rendered into the dom but it's contents are. For example;

<div @name="my-dialog" render-contents-only>
  <dialog if:="resultOK">...</dialog>
  <dialog if:="resultFail">...</dialog>
  <list if:="dialogClosed"> ... </list>
</div>

Naming stuff is hard, so please take my suggested attribute name with a pinch of salt. Only there to help this discussion.

Please note, I do appreciate that in many cases the recommended approach would be to design your system with a

<dialog @name="my-dialog"> 
</dialog>

and have the parent/host resposible for displaying either the dialog or the list. I do appreciate that. However, there are genuine requirements for clean controls to render different types of elements, and this is a very contrived example to limit the amount of example html to include. Having to have more nested controls for each combination of semantic parents might technically be "cleaner" but would break cohesion. So there's a trade off when your design can be too pure, too abstracted and the resulting code lacks cohesion. (that ability to easily reason about code and a system.)

@goblinfactory goblinfactory changed the title Should Nue's reactive components support empty parent elements <></> ? Should Nue's reactive components support empty parent fragment elements <></> ? Feb 12, 2024
@goblinfactory goblinfactory changed the title Should Nue's reactive components support empty parent fragment elements <></> ? Should Nue's reactive components support fragment elements <></> ? Feb 12, 2024
@nobkd nobkd added new feature New feature or request question Further information is requested labels Feb 12, 2024
@tipiirai
Copy link
Contributor

Yes. There are several use cases for this. I think Vue uses a <template> element as the parent component for this purpose.

@tipiirai tipiirai added low priority Done later and removed question Further information is requested labels Feb 23, 2024
@tipiirai tipiirai changed the title Should Nue's reactive components support fragment elements <></> ? Nue JS: Fragment support <></> Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority Done later new feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants