-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Automatic Mounting #75
Comments
Related to (2), once you register a tag with This is going to be tricky because currently
|
To summarize the above problem more clearly, there are 2 problems:
|
@matthewp could we check if the element is attached in the document? The fallback is to use mutation observers ... so only hooking up attached elements is fine. |
You could if you don't want |
on creation, we could use |
I'm not sure what you mean... |
This would mean calling the tagHandler in a |
No, I think he means doing this: customElements.define("foo-bar", class extends HTMLElement {
constructor() {
super();
if(this.ownerDocument.contains(this)) {
callbacks.tagHandler(this, { ... })
}
}
}) |
Ok. And if it's not in the document, set up a MutationObserver to listen for that element and call the tagHandler if it is inserted? |
You can use connectedCallback to know if it is inserted, but doing this would mean that elements created outside of stache behave differently from those created via |
We are definitely going to have this difference with the MutationObserver version, so it might be the best approach to just be consistent and do it this way all the time. The primary use-case for auto-mounting (I think) is so that people don't have to do all this in JSBin:
|
This is closed in major. |
This issue describes how we will make
can-view-callbacks
mount elements no matter how they are created (stache
,document.createElement
, etc). The steps to make this happen are outlined below:1. Define tags as customElements
For browsers that support customElements, we will use
customElements.define
to register tags as custom elements.2. Mark elements that are being created by stache
We will need to mark elements that are created by
can-stache
, so that we know they do not need to be "mounted" and we can avoid any performance degredation due to checking whether the element and its children need to be mounted. We will use a WeakSet to store these fragments.3. Create a MutationObserver
For browsers that do not support customElements, we will create a MutationObserver that will listen for when elements are added and "mount" them if they were not created by stache (not in the WeakSet created in step 2). This code will be something like:
4. Move Component autoMount code
This code: https://github.com/canjs/can-component/blob/major/can-component.js#L228-L238
can now be done when a tag is registered in a browser that does not support customElements.
The text was updated successfully, but these errors were encountered: