simpler isCustomElement & skip extra function call

- pass options.customElement down to mount_component
- remove expensive isCustomElement check
- only call add_render_callback if not customElement
pull/4522/head
hontas 6 years ago
parent 9cc7dd22f5
commit 1451a88082

@ -485,7 +485,7 @@ export default function dom(
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`} ${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
@init(this, { target: this.shadowRoot, props: ${init_props} }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${dirty}); @init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});
${dev_props_check} ${dev_props_check}

@ -53,27 +53,26 @@ export function claim_component(block, parent_nodes) {
block && block.l(parent_nodes); block && block.l(parent_nodes);
} }
export function mount_component(component, target, anchor) { export function mount_component(component, target, anchor, customElement) {
const { fragment, on_mount, on_destroy, after_update } = component.$$; const { fragment, on_mount, on_destroy, after_update } = component.$$;
const isCustomElement = Object.getPrototypeOf(component.constructor) === SvelteElement;
fragment && fragment.m(target, anchor); fragment && fragment.m(target, anchor);
// onMount happens before the initial afterUpdate if (!customElement) {
add_render_callback(() => { // onMount happens before the initial afterUpdate
// custom element on_mount is called in connectedCallback add_render_callback(() => {
if (isCustomElement) return;
const new_on_destroy = on_mount.map(run).filter(is_function);
const new_on_destroy = on_mount.map(run).filter(is_function); if (on_destroy) {
if (on_destroy) { on_destroy.push(...new_on_destroy);
on_destroy.push(...new_on_destroy); } else {
} else { // Edge case - component was destroyed immediately,
// Edge case - component was destroyed immediately, // most likely as a result of a binding initialising
// most likely as a result of a binding initialising run_all(new_on_destroy);
run_all(new_on_destroy); }
} component.$$.on_mount = [];
component.$$.on_mount = []; });
}); }
after_update.forEach(add_render_callback); after_update.forEach(add_render_callback);
} }
@ -161,7 +160,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
} }
if (options.intro) transition_in(component.$$.fragment); if (options.intro) transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor); mount_component(component, options.target, options.anchor, options.customElement);
flush(); flush();
} }

@ -40,7 +40,8 @@ class Component extends SvelteElement {
this, this,
{ {
target: this.shadowRoot, target: this.shadowRoot,
props: attribute_to_object(this.attributes) props: attribute_to_object(this.attributes),
customElement: true
}, },
null, null,
create_fragment, create_fragment,

Loading…
Cancel
Save