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

@rniwa Specifically to my case, `motor-node` elements` can only be children of (or be distributed into) `motor-scene` or other `motor-node` elements, or an error is to be thrown. My code will need to detect when a `motor-node` is attached or distributed into something other than a `motor-node` or `motor-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
1. `motor-node` can detect distributed `motor-node`s 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 are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/504#issuecomment-224099588

Received on Monday, 6 June 2016 21:50:55 UTC