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

@treshugart That case is easy to detect, but the case I'm trying to detect is different: I need to ensure that an element is slotted into another element of a certain type. With a closed tree, I don't see any possible way for a child to know it was slotted into some unexpected element. For example, if `<motor-node>` is slotted into a `<div>`, then I'd like to do something in that case, but the slotted `<motor-node>` can't detect this scenario. The only way I see to detect it currently is for child to emit an event, and if the parent of the slot that contains child is of the expected type, then that parent can signal to the child (in the event handler) that child was slotted correctly, but the task of the child firing an event can not happen at the specific moment in time right after the child has been slotted because the child has no idea when it is slotted (My [`distributedCallback`](https://github.com/w3c/webcomponents/issues/527) would help in this regard). If `distributedCallback` existed, then the child could fire an event in there, and if the child did not receive a response from a parent then the child would be able to make the assumption that said child was not slotted into an expected type of element and we can act upon that condition in a guaranteed manner.

---
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-229272057

Received on Wednesday, 29 June 2016 06:55:23 UTC