From 188edd2464bb545584f49b2f9e72a318bcc3579b Mon Sep 17 00:00:00 2001 From: Anton Samoylov Date: Sat, 27 Jul 2019 17:37:34 +0400 Subject: [PATCH] fix test after merge, move create_root_component_slots from utils.ts to Component.ts --- src/runtime/internal/Component.ts | 36 +++++++++- src/runtime/internal/utils.ts | 36 ---------- .../samples/root-component-slot/expected.js | 69 ++++++++----------- 3 files changed, 63 insertions(+), 78 deletions(-) diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 10588a0804..9fc4488541 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -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_function, run, run_all, noop } from './utils'; -import { children } from './dom'; +import { children, insert, detach } from './dom'; import { transition_in } from './transitions'; interface Fragment { @@ -226,3 +226,37 @@ export class SvelteComponent { // overridden by instance, if it has props } } + +function create_root_component_slot_fn(elements) { + return function create_root_component_slot() { + return { + c: noop, + + m: function mount(target, anchor) { + elements.forEach(element => { + insert(target, element, anchor); + }); + }, + + d: function destroy(detaching) { + if (detaching) { + elements.forEach(element => detach(element)); + } + }, + + l: noop, + }; + }; +} + +export function create_root_component_slots(slots) { + const root_component_slots = {}; + for (const slot_name in slots) { + let elements = slots[slot_name]; + if (!Array.isArray(elements)) { + elements = [elements]; + } + root_component_slots[slot_name] = [create_root_component_slot_fn(elements)]; + } + return root_component_slots; +} diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 7f212de483..5791cbbe30 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -1,5 +1,3 @@ -import { insert, detach } from './dom'; - export function noop() {} export const identity = x => x; @@ -130,37 +128,3 @@ export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, export function action_destroyer(action_result) { return action_result && is_function(action_result.destroy) ? action_result.destroy : noop; } - -function create_root_component_slot_fn(elements) { - return function create_root_component_slot() { - return { - c: noop, - - m: function mount(target, anchor) { - elements.forEach(element => { - insert(target, element, anchor); - }); - }, - - d: function destroy(detaching) { - if (detaching) { - elements.forEach(element => detach(element)); - } - }, - - l: noop, - }; - }; -} - -export function create_root_component_slots(slots) { - const root_component_slots = {}; - for (const slot_name in slots) { - let elements = slots[slot_name]; - if (!Array.isArray(elements)) { - elements = [elements]; - } - root_component_slots[slot_name] = [create_root_component_slot_fn(elements)]; - } - return root_component_slots; -} \ No newline at end of file diff --git a/test/js/samples/root-component-slot/expected.js b/test/js/samples/root-component-slot/expected.js index 1397300ace..de22b52083 100644 --- a/test/js/samples/root-component-slot/expected.js +++ b/test/js/samples/root-component-slot/expected.js @@ -11,37 +11,30 @@ import { init, insert, safe_not_equal, - space + space, + transition_in, + transition_out } from "svelte/internal"; -const get_slot1_slot_changes = ({}) => ({}); -const get_slot1_slot_context = ({}) => ({}); +const get_slot1_slot_changes = dirty => ({}); +const get_slot1_slot_context = ctx => ({}); function create_fragment(ctx) { - var div, t, current; - - const default_slot_1 = ctx.$$slots.default; - const default_slot = create_slot(default_slot_1, ctx, null); - - const slot1_slot_1 = ctx.$$slots.slot1; - const slot1_slot = create_slot(slot1_slot_1, ctx, get_slot1_slot_context); + let div; + let t; + let current; + const default_slot_template = /*$$slots*/ ctx[1].default; + const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[0], null); + const slot1_slot_template = /*$$slots*/ ctx[1].slot1; + const slot1_slot = create_slot(slot1_slot_template, ctx, /*$$scope*/ ctx[0], get_slot1_slot_context); return { c() { div = element("div"); - if (default_slot) default_slot.c(); t = space(); - if (slot1_slot) slot1_slot.c(); }, - - l(nodes) { - if (default_slot) default_slot.l(div_nodes); - - if (slot1_slot) slot1_slot.l(div_nodes); - }, - m(target, anchor) { insert(target, div, anchor); @@ -57,37 +50,29 @@ function create_fragment(ctx) { current = true; }, - - p(changed, ctx) { - if (default_slot && default_slot.p && changed.$$scope) { - default_slot.p(get_slot_changes(default_slot_1, ctx, changed,), get_slot_context(default_slot_1, ctx, null)); + p(ctx, [dirty]) { + if (default_slot && default_slot.p && dirty & /*$$scope*/ 1) { + default_slot.p(get_slot_context(default_slot_template, ctx, /*$$scope*/ ctx[0], null), get_slot_changes(default_slot_template, /*$$scope*/ ctx[0], dirty, null)); } - if (slot1_slot && slot1_slot.p && changed.$$scope) { - slot1_slot.p(get_slot_changes(slot1_slot_1, ctx, changed, get_slot1_slot_changes), get_slot_context(slot1_slot_1, ctx, get_slot1_slot_context)); + if (slot1_slot && slot1_slot.p && dirty & /*$$scope*/ 1) { + slot1_slot.p(get_slot_context(slot1_slot_template, ctx, /*$$scope*/ ctx[0], get_slot1_slot_context), get_slot_changes(slot1_slot_template, /*$$scope*/ ctx[0], dirty, get_slot1_slot_changes)); } }, - i(local) { if (current) return; - if (default_slot && default_slot.i) default_slot.i(local); - if (slot1_slot && slot1_slot.i) slot1_slot.i(local); + transition_in(default_slot, local); + transition_in(slot1_slot, local); current = true; }, - o(local) { - if (default_slot && default_slot.o) default_slot.o(local); - if (slot1_slot && slot1_slot.o) slot1_slot.o(local); + transition_out(default_slot, local); + transition_out(slot1_slot, local); current = false; }, - d(detaching) { - if (detaching) { - detach(div); - } - + if (detaching) detach(div); if (default_slot) default_slot.d(detaching); - if (slot1_slot) slot1_slot.d(detaching); } }; @@ -97,22 +82,24 @@ function instance($$self, $$props, $$invalidate) { let { $$slots = {}, $$scope } = $$props; $$self.$set = $$props => { - if ('$$scope' in $$props) $$invalidate('$$scope', $$scope = $$props.$$scope); + if ("$$scope" in $$props) $$invalidate(0, $$scope = $$props.$$scope); }; - return { $$slots, $$scope }; + return [$$scope, $$slots]; } class Component extends SvelteComponent { constructor(options) { super(); + if (options.slots) { options.props = options.props || {}; options.props.$$scope = {}; options.props.$$slots = create_root_component_slots(options.slots); } - init(this, options, instance, create_fragment, safe_not_equal, []); + + init(this, options, instance, create_fragment, safe_not_equal, {}); } } -export default Component; +export default Component; \ No newline at end of file