refactor add_css_to_component to not save customStyleTag in component.$$

pull/5639/head
Ivan Hofer 5 years ago
parent e8065eb22e
commit b38e2b7b9a

@ -44,8 +44,8 @@ export default function dom(
if (should_add_css) {
body.push(b`
function ${add_css}(target) {
@append_style_if_not_present(target, "${component.stylesheet.id.replace('svelte-', '')}", "${styles}");
function ${add_css}(options) {
@add_css_to_component(options, "${component.stylesheet.id.replace('svelte-', '')}", "${styles}");
}
`);
}
@ -529,7 +529,7 @@ export default function dom(
constructor(options) {
super(${options.dev && 'options'});
${should_add_css && b`@add_css_to_component(this, ${add_css}, options);`}
${should_add_css && b`${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 });`}

@ -1,7 +1,7 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_empty, is_function, run, run_all, noop } from './utils';
import { children, detach } from './dom';
import { append, children, detach, element } from './dom';
import { transition_in } from './transitions';
interface Fragment {
@ -100,9 +100,20 @@ function make_dirty(component, i) {
let appendStylesTo = document.head;
export function add_css_to_component(add_css, { customStyleTag }) {
export function add_css_to_component(
{ customStyleTag },
styleSheetId: string,
styles: string,
styleId:string = `svelte-${styleSheetId}-style`) {
if (customStyleTag) appendStylesTo = customStyleTag;
add_css(appendStylesTo);
if (!appendStylesTo.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;
style.textContent = styles;
append(appendStylesTo, style);
}
}
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {

@ -1,18 +1,5 @@
import { has_prop } from './utils';
export function append_style_if_not_present(
target: Element,
styleSheetId: string,
styles: string,
styleId:string = `svelte-${styleSheetId}-style`) {
if (!target.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;
style.textContent = styles;
append(target, style);
}
}
export function append(target: Node, node: Node) {
target.appendChild(node);
}

Loading…
Cancel
Save