Re: [webcomponents] Add authoring guidance for writing custom element constructors (#409)

Regarding doing work in an attachedCallback: if an element is removed and then re-inserted, it's my understanding that the attachedCallback will run again. If that's the case, you may want to clarify that any *one time* initialization in the attachedCallback needs to be explicitly set up that way.

E.g., we have components that, in their createdCallback, add event listeners to the host or an element in their shadow subtree). It sounds like we should move most of that code to attachedCallback — but we only want to wire up the event listeners once. That suggests creating a private flag to keep track of whether we've already done this one-time initialization work so that, in the event the element is detached and then later reattached, we don't inadvertently perform that initialization again.

If I've got that right, would that be worth documenting? It seems likely that people will fail to account for the reattachment scenario. I also want to make sure we document best practices for the "Reattachment" item in the [Gold Standard checklist for web components](https://github.com/webcomponents/gold-standard/wiki).

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/409#issuecomment-195119284

Received on Friday, 11 March 2016 00:41:35 UTC