disconnecting mutation observer on disconnect

pull/4348/head
Cris Ward 6 years ago
parent f591085714
commit a2ac1d91fa

@ -446,8 +446,8 @@ export default function dom(
this._root =this.attachShadow({ mode: '${options.shadowDom}' }); this._root =this.attachShadow({ mode: '${options.shadowDom}' });
` || b` ` || b`
this._copycontent(); this._copycontent();
const observer = new MutationObserver(() => this._slotcontent()); this.slotObserver = new MutationObserver(() => this._slotcontent());
observer.observe(this, {childList: true, subtree: true}); this.slotObserver.observe(this, {childList: true, subtree: true});
`} `}
${css.code && !lightDom && b`this._root.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`} ${css.code && !lightDom && b`this._root.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
${should_add_css && lightDom && b`if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`} ${should_add_css && lightDom && b`if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`}
@ -544,6 +544,17 @@ export default function dom(
} }
}` as FunctionExpression }` as FunctionExpression
}); });
declaration.body.body.push({
type: 'MethodDefinition',
kind: 'method',
static: false,
computed: false,
key: { type: 'Identifier', name: 'disconnectedCallback' },
value: x`function() {
this.slotObserver.disconnect();
}` as FunctionExpression
});
} }
declaration.body.body.push(...accessors); declaration.body.body.push(...accessors);

Loading…
Cancel
Save