From 81285112c9f99ae7ba618089cfef194864190f83 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 | 37 ------------------- .../samples/root-component-slot/expected.js | 18 +++++---- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 92e227e57c..cdae6b3191 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'; // eslint-disable-next-line @typescript-eslint/class-name-casing @@ -213,3 +213,37 @@ export class SvelteComponentDev extends SvelteComponent { }; } } + +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 645c3cc11d..08410ec33a 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; @@ -83,7 +81,6 @@ export function exclude_internal_props(props) { return result; } - export function once(fn) { let ran = false; return function(this: any, ...args) { @@ -92,37 +89,3 @@ export function once(fn) { fn.call(this, ...args); }; } - -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/test/js/samples/root-component-slot/expected.js b/test/js/samples/root-component-slot/expected.js index 1397300ace..8571b53b98 100644 --- a/test/js/samples/root-component-slot/expected.js +++ b/test/js/samples/root-component-slot/expected.js @@ -11,11 +11,13 @@ 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 = () => ({}); +const get_slot1_slot_context = () => ({}); function create_fragment(ctx) { var div, t, current; @@ -60,7 +62,7 @@ function create_fragment(ctx) { 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)); + default_slot.p(get_slot_changes(default_slot_1, ctx, changed, null), get_slot_context(default_slot_1, ctx, null)); } if (slot1_slot && slot1_slot.p && changed.$$scope) { @@ -70,14 +72,14 @@ function create_fragment(ctx) { 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; },