Re: [webcomponents] Replace attached/detached callbacks with insertedIntoDocument/removedFromDocument (#362)

Looking at the history, and recalling from memory, seems there have been several changes here:

- `insertedCallback` / `removedCallback`
- `enteredViewCallback` / `leftViewCallback`
- `enteredDocumentCallback` / `leftDocumentCallback`
- `attachedCallback` / `detachedCallback`
- `connected` / `disconnected`?

I asked around at work and someone said:

> imo, connected seems to mean that the 2 connected objects are more freely independent of each other. Whereas attached has a less flexible context.

> like you'd say a leech was attached to your body, not connected to your body.

Others seemed to agree that `attached` and `detached` are the best fit.

In terms of consistency:

- `inserted` -> `Node.insertBefore()`
- `attached` -> `HTMLElement.attachShadowRoot()`
- `disconnected` -> `MutationObserver.disconnect()`

The closest in terms of semantics seems to be `inserted` and `Node.insertBefore()`. IIRC `insertedCallback` and `removedCallback` were the original variations and were also used by Chrome's first implementation.

I think the most important thing here is that names are descriptive, consistent with each other and don't change in the future. I'd vote for `attachedToDocument` and `detachedFromDocument` which leaves you open to use `attachedToNode` and `detachedFromNode` if that behaviour is to be re-implemented in the future.

Whatever happened to [using symbols](https://github.com/w3c/webcomponents/wiki/Custom-Elements:-Contentious-Bits#symbol-named-properties-for-lifecycle-hooks)?


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

Received on Wednesday, 3 February 2016 23:59:55 UTC