Skip to content

Commit 9678ca5

Browse files
Anton Samoylovtanhauhau
Anton Samoylov
authored andcommitted
fix test after merge, move create_root_component_slots from utils.ts to Component.ts
1 parent 2c4d21a commit 9678ca5

File tree

3 files changed

+64
-79
lines changed

3 files changed

+64
-79
lines changed

src/runtime/internal/Component.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
22
import { current_component, set_current_component } from './lifecycle';
33
import { blank_object, is_function, run, run_all, noop } from './utils';
4-
import { children } from './dom';
4+
import { children, insert, detach } from './dom';
55
import { transition_in } from './transitions';
66

77
interface Fragment {
@@ -226,3 +226,37 @@ export class SvelteComponent {
226226
// overridden by instance, if it has props
227227
}
228228
}
229+
230+
function create_root_component_slot_fn(elements) {
231+
return function create_root_component_slot() {
232+
return {
233+
c: noop,
234+
235+
m: function mount(target, anchor) {
236+
elements.forEach(element => {
237+
insert(target, element, anchor);
238+
});
239+
},
240+
241+
d: function destroy(detaching) {
242+
if (detaching) {
243+
elements.forEach(element => detach(element));
244+
}
245+
},
246+
247+
l: noop,
248+
};
249+
};
250+
}
251+
252+
export function create_root_component_slots(slots) {
253+
const root_component_slots = {};
254+
for (const slot_name in slots) {
255+
let elements = slots[slot_name];
256+
if (!Array.isArray(elements)) {
257+
elements = [elements];
258+
}
259+
root_component_slots[slot_name] = [create_root_component_slot_fn(elements)];
260+
}
261+
return root_component_slots;
262+
}

src/runtime/internal/utils.ts

-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { insert, detach } from './dom';
2-
31
export function noop() {}
42

53
export const identity = x => x;
@@ -127,37 +125,3 @@ export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj,
127125
export function action_destroyer(action_result) {
128126
return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
129127
}
130-
131-
function create_root_component_slot_fn(elements) {
132-
return function create_root_component_slot() {
133-
return {
134-
c: noop,
135-
136-
m: function mount(target, anchor) {
137-
elements.forEach(element => {
138-
insert(target, element, anchor);
139-
});
140-
},
141-
142-
d: function destroy(detaching) {
143-
if (detaching) {
144-
elements.forEach(element => detach(element));
145-
}
146-
},
147-
148-
l: noop,
149-
};
150-
};
151-
}
152-
153-
export function create_root_component_slots(slots) {
154-
const root_component_slots = {};
155-
for (const slot_name in slots) {
156-
let elements = slots[slot_name];
157-
if (!Array.isArray(elements)) {
158-
elements = [elements];
159-
}
160-
root_component_slots[slot_name] = [create_root_component_slot_fn(elements)];
161-
}
162-
return root_component_slots;
163-
}

test/js/samples/root-component-slot/expected.js

+29-42
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,30 @@ import {
1111
init,
1212
insert,
1313
safe_not_equal,
14-
space
14+
space,
15+
transition_in,
16+
transition_out
1517
} from "svelte/internal";
1618

17-
const get_slot1_slot_changes = ({}) => ({});
18-
const get_slot1_slot_context = ({}) => ({});
19+
const get_slot1_slot_changes = dirty => ({});
20+
const get_slot1_slot_context = ctx => ({});
1921

2022
function create_fragment(ctx) {
21-
var div, t, current;
22-
23-
const default_slot_1 = ctx.$$slots.default;
24-
const default_slot = create_slot(default_slot_1, ctx, null);
25-
26-
const slot1_slot_1 = ctx.$$slots.slot1;
27-
const slot1_slot = create_slot(slot1_slot_1, ctx, get_slot1_slot_context);
23+
let div;
24+
let t;
25+
let current;
26+
const default_slot_template = /*$$slots*/ ctx[1].default;
27+
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[0], null);
28+
const slot1_slot_template = /*$$slots*/ ctx[1].slot1;
29+
const slot1_slot = create_slot(slot1_slot_template, ctx, /*$$scope*/ ctx[0], get_slot1_slot_context);
2830

2931
return {
3032
c() {
3133
div = element("div");
32-
3334
if (default_slot) default_slot.c();
3435
t = space();
35-
3636
if (slot1_slot) slot1_slot.c();
3737
},
38-
39-
l(nodes) {
40-
if (default_slot) default_slot.l(div_nodes);
41-
42-
if (slot1_slot) slot1_slot.l(div_nodes);
43-
},
44-
4538
m(target, anchor) {
4639
insert(target, div, anchor);
4740

@@ -57,37 +50,29 @@ function create_fragment(ctx) {
5750

5851
current = true;
5952
},
60-
61-
p(changed, ctx) {
62-
if (default_slot && default_slot.p && changed.$$scope) {
63-
default_slot.p(get_slot_changes(default_slot_1, ctx, changed,), get_slot_context(default_slot_1, ctx, null));
53+
p(ctx, [dirty]) {
54+
if (default_slot && default_slot.p && dirty & /*$$scope*/ 1) {
55+
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));
6456
}
6557

66-
if (slot1_slot && slot1_slot.p && changed.$$scope) {
67-
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));
58+
if (slot1_slot && slot1_slot.p && dirty & /*$$scope*/ 1) {
59+
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));
6860
}
6961
},
70-
7162
i(local) {
7263
if (current) return;
73-
if (default_slot && default_slot.i) default_slot.i(local);
74-
if (slot1_slot && slot1_slot.i) slot1_slot.i(local);
64+
transition_in(default_slot, local);
65+
transition_in(slot1_slot, local);
7566
current = true;
7667
},
77-
7868
o(local) {
79-
if (default_slot && default_slot.o) default_slot.o(local);
80-
if (slot1_slot && slot1_slot.o) slot1_slot.o(local);
69+
transition_out(default_slot, local);
70+
transition_out(slot1_slot, local);
8171
current = false;
8272
},
83-
8473
d(detaching) {
85-
if (detaching) {
86-
detach(div);
87-
}
88-
74+
if (detaching) detach(div);
8975
if (default_slot) default_slot.d(detaching);
90-
9176
if (slot1_slot) slot1_slot.d(detaching);
9277
}
9378
};
@@ -97,22 +82,24 @@ function instance($$self, $$props, $$invalidate) {
9782
let { $$slots = {}, $$scope } = $$props;
9883

9984
$$self.$set = $$props => {
100-
if ('$$scope' in $$props) $$invalidate('$$scope', $$scope = $$props.$$scope);
85+
if ("$$scope" in $$props) $$invalidate(0, $$scope = $$props.$$scope);
10186
};
10287

103-
return { $$slots, $$scope };
88+
return [$$scope, $$slots];
10489
}
10590

10691
class Component extends SvelteComponent {
10792
constructor(options) {
10893
super();
94+
10995
if (options.slots) {
110-
options.props = options.props || {};
96+
options.props = options.props || ({});
11197
options.props.$$scope = {};
11298
options.props.$$slots = create_root_component_slots(options.slots);
11399
}
114-
init(this, options, instance, create_fragment, safe_not_equal, []);
100+
101+
init(this, options, instance, create_fragment, safe_not_equal, {});
115102
}
116103
}
117104

118-
export default Component;
105+
export default Component;

0 commit comments

Comments
 (0)