Re: [w3c/webcomponents] How can a custom element detect when it is transcluded into a shadow tree (slotchange)? (#504)

Can you expand on your specific use case? It seems wrong that a child
should know anything about their ancestor tree as it breaks encapsulation.
Parents wrapping children should augment the behaviour of descendants
through events, but descendants should not couple their logic to the
ancestor tree.

On Tue, 7 Jun 2016, 07:50 Joseph Orbegoso Pea <notifications@github.com>
wrote:

> @rniwa <https://github.com/rniwa> Specifically to my case, motor-node
> elementscan only be children of (or be distributed into)motor-sceneor
> othermotor-nodeelements, or an error is to be thrown. My code will need
> to detect when amotor-nodeis attached or distributed into something other
> than amotor-nodeormotor-scene`.
>
> I see how to detect the following two cases and throw errors for them:
>
>    1. motor-node can easily detect when child motor-node element is
>    attached with MutationObserver
>    2. motor-node can detect distributed motor-nodes with slotchange.
>
> But I am having trouble figuring out how to deal with this scenario:
>
>    1. motor-node is appended to something other than motor-node. The
>    child can easily observe when this happens. f.e. when motor-node is
>    appended to a div there should be an error. But, the problem is: if
>    the div has a ShadowDOM root (now or in the future) and the motor-node
>    gets distributed into the div's inner tree into a slot element of an
>    inner motor-node, then that is fine and there shouldn't be an error
>    thrown. Furthermore, if a motor-node gets distributed into an inner
>    tree and the slot-containing element is not a motor-node then there
>    needs to be an error, and that case seems impossible to catch (with closed
>    trees).
>
> Basically, this is fine, and a parent motor-node can easily detect this:
>
>               <motor-node> <!-- this is the "parent" -->
>                    |
>                    |
>                 <slot>
>                    |
>                    |
>               <motor-node> <!-- this is the "child", detected by "parent" via slotchange -->
>
> But, the following is wrong, and I would like to throw a helpful error to
> the end user so they can learn from it:
>
>                 <div> <!-- Error, not a motor-node element -->
>                    |
>                    |
>                 <slot>
>                    |
>                    |
>               <motor-node>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/w3c/webcomponents/issues/504#issuecomment-224099588>,
> or mute the thread
> <https://github.com/notifications/unsubscribe/AAIVbHzjTmvHC_19vvI26pDH5S6kKC5fks5qJJYdgaJpZM4IkCcX>
> .
>


---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/504#issuecomment-224114736

Received on Monday, 6 June 2016 23:02:02 UTC