Skip to content

fix: CustomElement constructor for compatibility with other polyfills #27

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

Merged
merged 2 commits into from
Aug 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export default function wrap (Vue, Component) {
}

class CustomElement extends HTMLElement {
constructor () {
super()
this.attachShadow({ mode: 'open' })
constructor (...args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ...args are necessary here, are they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const self = super(...args)
self.attachShadow({ mode: 'open' })

const wrapper = this._wrapper = new Vue({
const wrapper = self._wrapper = new Vue({
name: 'shadow-root',
customElement: this,
shadowRoot: this.shadowRoot,
customElement: self,
shadowRoot: self.shadowRoot,
data () {
return {
props: {},
Expand All @@ -106,20 +106,20 @@ export default function wrap (Vue, Component) {
let hasChildrenChange = false
for (let i = 0; i < mutations.length; i++) {
const m = mutations[i]
if (isInitialized && m.type === 'attributes' && m.target === this) {
syncAttribute(this, m.attributeName)
if (isInitialized && m.type === 'attributes' && m.target === self) {
syncAttribute(self, m.attributeName)
} else {
hasChildrenChange = true
}
}
if (hasChildrenChange) {
wrapper.slotChildren = Object.freeze(toVNodes(
wrapper.$createElement,
this.childNodes
self.childNodes
))
}
})
observer.observe(this, {
observer.observe(self, {
childList: true,
subtree: true,
characterData: true,
Expand Down