- From: André Gomes <notifications@github.com>
- Date: Fri, 30 Jul 2021 13:08:17 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/509/890127036@github.com>
Yes, that clarifies a lot. And I'm sorry if I went off topic, I'm just trying to collaborate since you asked what we think of the APIs. After your explanations I can see I was misusing connected/disconnected callbacks as observed/unobserved callbacks. And, honestly, setup/teardown could be done alongside `eo.observe(el)` and `eo.disconnect(el)`, like in my [updated example](https://stackblitz.com/edit/element-observer-gyfmmk?file=directive%2Fcounter.js), so I don't think you need to rename the existing callbacks or creating new ones. It's good enough the way they are. The beauty of this ElementObserver (or element-behaviors) is that they make it easy to define reusable behaviors that you can apply to standard or custom elements. It's also good that the relationship between elements and behaviors is many-to-many, unlike in `is=""` (in my updated example I created a behavior to add a counter to an element, and another one to enforce a threshold on the element's value). That said, I'd only rename `eo.disconnect(el)` to `eo.unobserve(el)` in ElementObserver API to avoid the confusion with `disconnectedCallback`. Also, it's valid to note that the callback order is correct as long as we don't mix connect/disconnect with attr changed events in a single run like I did, otherwise attr changed will always be called after connect/disconnect events. It doesn't matter much, though, since the callbacks have `el.isConnected` and the final attr value to easily determine the element's current state. So, if it's too much trouble to avoid multiple calls, don't worry with that. It's expected due to MutationObserver, as you said. Thank you for your attention and hard-work. I'm looking forward to see @trusktr 's opinions too. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/509#issuecomment-890127036
Received on Friday, 30 July 2021 20:08:29 UTC