refactor add styles method call to reduce generated output

pull/5639/head
Ivan Hofer 5 years ago
parent bf528d16b4
commit 5ad396b6b2

@ -528,7 +528,10 @@ export default function dom(
class ${name} extends ${superclass} { class ${name} extends ${superclass} {
constructor(options) { constructor(options) {
super(${options.dev && 'options'}); super(${options.dev && 'options'});
@init(this, options, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${should_add_css ? add_css : x`@noop`}, ${dirty});
${should_add_css && b`@addCssToComponent(this, add_css, options);`}
@init(this, options, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});
${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`} ${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`}
${dev_props_check} ${dev_props_check}

@ -34,7 +34,7 @@ interface T$$ {
on_mount: any[]; on_mount: any[];
on_destroy: any[]; on_destroy: any[];
skip_bound: boolean; skip_bound: boolean;
customStyleTag: HTMLElement; customStyleTag?: HTMLElement;
} }
export function bind(component, name, callback) { export function bind(component, name, callback) {
@ -97,18 +97,26 @@ function make_dirty(component, i) {
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
} }
export function init(component, options, instance, create_fragment, not_equal, props, add_css, dirty = [-1]) {
export function addCssToComponent(that, add_css, options) {
that.$$ = {
customStyleTag: options.customStyleTag || current_component && current_component.$$.customStyleTag
};
add_css(that.$$.customStyleTag);
}
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
const parent_component = current_component; const parent_component = current_component;
set_current_component(component); set_current_component(component);
const prop_values = options.props || {}; const prop_values = options.props || {};
const $$: T$$ = component.$$ = { const $$: T$$ = component.$$ = {
...component.$$,
fragment: null, fragment: null,
ctx: null, ctx: null,
customStyleTag: options.customStyleTag || parent_component && parent_component.$$.customStyleTag,
// state // state
props, props,
update: noop, update: noop,
@ -130,8 +138,6 @@ export function init(component, options, instance, create_fragment, not_equal, p
let ready = false; let ready = false;
add_css($$.customStyleTag);
$$.ctx = instance $$.ctx = instance
? instance(component, prop_values, (i, ret, ...rest) => { ? instance(component, prop_values, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret; const value = rest.length ? rest[0] : ret;

Loading…
Cancel
Save