Skip to content

Commit 49c5e8f

Browse files
author
lishiwen
committed
added name slots
1 parent 12cf2f5 commit 49c5e8f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

lib/m-vue.cjs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,19 @@ const ComponentPublicInstanceHandlers = {
191191
};
192192

193193
function initSlots(instance, instanceChildren) {
194+
instance.slots = normalizeObjectSlots(instanceChildren);
195+
}
196+
function normalizeObjectSlots(instanceChildren) {
194197
let slots = {};
195198
if (isStructObject(instanceChildren)) {
196199
for (const key in instanceChildren) {
197-
const slot = instanceChildren[key];
198-
slots[key] = isArray(slot) ? slot : [slot];
200+
slots[key] = normalizeSlot(instanceChildren[key]);
199201
}
200202
}
201-
instance.slots = slots;
203+
return slots;
204+
}
205+
function normalizeSlot(value) {
206+
return isArray(value) ? value : [value];
202207
}
203208

204209
function promiseEmit() { }

lib/m-vue.esm.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,19 @@ const ComponentPublicInstanceHandlers = {
187187
};
188188

189189
function initSlots(instance, instanceChildren) {
190+
instance.slots = normalizeObjectSlots(instanceChildren);
191+
}
192+
function normalizeObjectSlots(instanceChildren) {
190193
let slots = {};
191194
if (isStructObject(instanceChildren)) {
192195
for (const key in instanceChildren) {
193-
const slot = instanceChildren[key];
194-
slots[key] = isArray(slot) ? slot : [slot];
196+
slots[key] = normalizeSlot(instanceChildren[key]);
195197
}
196198
}
197-
instance.slots = slots;
199+
return slots;
200+
}
201+
function normalizeSlot(value) {
202+
return isArray(value) ? value : [value];
198203
}
199204

200205
function promiseEmit() { }

src/runtime-core/componentSlots.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { isArray, isStructObject } from "../shared/type";
22

33
export function initSlots(instance, instanceChildren) {
4+
instance.slots = normalizeObjectSlots(instanceChildren);
5+
};
6+
7+
export function normalizeObjectSlots(instanceChildren) {
48
let slots = {};
59
if (isStructObject(instanceChildren)) {
610
for (const key in instanceChildren) {
7-
const slot = instanceChildren[key];
8-
slots[key] = isArray(slot) ? slot : [slot];
11+
slots[key] = normalizeSlot(instanceChildren[key]);
912
}
1013
};
11-
instance.slots = slots;
12-
};
14+
return slots;
15+
}
16+
17+
export function normalizeSlot(value) {
18+
return isArray(value) ? value : [value];
19+
}

0 commit comments

Comments
 (0)