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

@annevk 

> What is debounced?

https://github.com/component/debounce
[debounce](https://github.com/component/debounce) 

It uses `setTimeout()` - thus queueing a task - but it ensures that it only gets fired once after repeated synchronous calls to that method are invoked, meaning multiple slot changes are batched into a single event.

> Also, it looks like your event is dispatched synchronously.

Do you mean synchronous as in `dispatchEvent()` is synchronous, or do you mean synchronous as in you read it like an event would fire for every single mutation instead of being batched? If the former, I don't have any idea how I'd do that in polyfill-land. If the latter, then [debounce](https://github.com/component/debounce) does make it "async".

I've thought about doing the same thing with `requestAnimationFrame()` to get closer to what's being described in this thread but haven't got around to it yet. Unfortunately, I don't think there is a better way to get closer to what's described here, in polyfill-land.

Even though it's currently using tasks, we have the ability to do our own bookkeeping, so we know when and where changes have happened even if UI changes have happened between queueing a task to trigger the event and when the event eventually gets fired. When the task is executed and just before the event is fired, we can take the records and attach them to the event detail if need be. We don't currently do this, but it's fairly trivial to implement for a given slot's assigned nodes (not deep).

The alternative - as has already been explained - would be to leave it up to the user to diff the previous state with the new state. This is [definitely doable](https://github.com/skatejs/dom-diff). We haven't come up with a use case warranting knowing the exact changes yet for a slot change, but we also only *just* starting to use it in anger.

If it'd be helpful, I'm happy to try and see what I can do in terms of spiking a mutation observer implementation in the polyfill.

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

Received on Wednesday, 30 March 2016 09:55:49 UTC