templating icon indicating copy to clipboard operation
templating copied to clipboard

Support nested elements on @child and @children

Open davismj opened this issue 7 years ago • 7 comments

I'm submitting a feature request

Current behavior:

@children and @child select immediate children only.

  • What is the expected behavior?

@children and @child should select arbitrary nested children.

  • What is the motivation / use case for changing the behavior?

This is a great and important feature, and it is a shame that it boxes you into structuring your markup a particular way.

If the reason for limiting to immediate children was performance, this could be configurable:

@children('my-element') a; // immediate children
@children({ selector: 'my-element', recursive: true }) b; // all children

davismj avatar Mar 07 '18 07:03 davismj

https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver Could directly map to 'subtree' option Recursive is not expected in context of dom/css i guess. Thought to write recursive is not right.. but then thought about file systems.. and yeah it is right word.. just not in context of css selectors (-:

Alexander-Taran avatar Mar 07 '18 23:03 Alexander-Taran

@bigopon thoughts?

davismj avatar Mar 21 '18 05:03 davismj

#590 is the issue related to @children. It will cause the <slot/> and @children not working properly together. This feature, theoretically, can work without that fix, as you can target its own content, but I think it's better to wait for that fix to be merged / discussed before we go ahead with this. I'm not sure what we would do in recursive case though ? do we count them as 1, or 1 + all children with the same selector ?

fix #590 is waiting for @jdanyow @EisenbergEffect 's review

bigopon avatar Mar 21 '18 05:03 bigopon

I'm not sure what we would do in recursive case though ? do we count them as 1, or 1 + all children with the same selector ?

I don't follow. @children('foo') should be populated with an array of 3 FooCustomElement for the following view:

<template>
  <foo></foo>
  <ul>
    <li><foo></foo></li>
  </ul>
  <foo></foo>
</template>

davismj avatar Mar 21 '18 07:03 davismj

if we have something like this rendered

<app>
  <tree>
    <tree-node>
      <tree>
        <tree-node>...</tree-node>
      </tree>
    </tree-node>
</app>

What would @children('tree-node') return ?

bigopon avatar Mar 21 '18 08:03 bigopon

On app, an array of two TreeNodeCustomElements.

davismj avatar Mar 21 '18 08:03 davismj

Since #590 is closed, can this be closed as well?

tmueller avatar Nov 14 '18 16:11 tmueller