Re: [webcomponents] Need "slotchange" event (#288)

I think regardless of what approach we take, the only reasonable way to specify this is by running "distribution" during insert/remove operations. That seems expensive since lots of changes can affect distribution. Hopefully implementations can find ways to optimize.

So, during insert/remove we will have figured out whether new nodes are distributed to a slot.

If we want to use mutation observers, I suggest that at the end of insert/remove, if a slot element's distributed content has changed, we queue a mutation record whose type is "slot", target is the slot element, and everything else is empty/null. That seems reasonably simple.

If we don't want to use mutation observers, I suggest that again at the end of insert/remove, and if a slot element's distributed content has changed, we queue a microtask to dispatch an event at the slot element. Now, if it's really too expensive that this event would traverse the tree, we could give `<slot>` some kind of `<slot>.events` event target object and dispatch the change event there, but that gets a little ugly (and requires an extra object per slot).

Having written this up I think I favor mutation records, but @ajklein not leaning in that direction makes me a little wary.

---
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/288#issuecomment-202382615

Received on Monday, 28 March 2016 13:03:19 UTC