Skip to content

Commit 6a0a1f8

Browse files
author
lishiwen
committed
added slots
1 parent e3c4838 commit 6a0a1f8

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

src/runtime-core/component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isStructObject } from "../shared/type";
33
import { emit, extendRuntimeInstance } from "./componentEmit";
44
import { initProps } from "./componentProps";
55
import { ComponentPublicInstanceHandlers } from "./componentPublicInstance";
6+
import { initSlots } from "./componentSlots";
67

78
// TODO: runtime instance extend
89
// NOTE: 这是自己扩展的
@@ -15,6 +16,7 @@ export function createComponentInstance(vnode) {
1516
type: vnode.type,
1617
setupState: {},
1718
props: {},
19+
slots: {},
1820
emit: (instance, event) => { },
1921
};
2022

@@ -30,7 +32,7 @@ export function createComponentInstance(vnode) {
3032

3133
export function setupComponent(instance) {
3234
initProps(instance, instance.vnode.props);
33-
// initSlots();
35+
initSlots(instance, instance.vnode.children);
3436
setupStatefulComponent(instance);
3537
}
3638

src/runtime-core/componentEmit.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ export function emit(instance, eventProperty, ...args) {
1414

1515
// TODO: 运行时扩展实例
1616
export function extendRuntimeInstance(instance, extendApis = {}) {
17-
console.log("extendApis", extendApis);
1817
// XXX: 临时解决方案
1918
// TODO: 待完善扩展实例
2019
Object.keys(extendApis).forEach(key => {
2120
instance[key] = extendApis[key];
22-
console.log(key, extendApis[key])
2321
});
2422
}

src/runtime-core/componentPublicInstance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { hasOwnProperty } from "../shared/index";
22

33
export const PublicPropertiesMaps = {
4-
"$el": (instance) => instance.vnode.el,
4+
$el: (instance) => instance.vnode.el,
5+
$slots: (instance) => instance.slots,
56
};
67
export const ComponentPublicInstanceHandlers = {
78
get({ _instance }, key) {

src/runtime-core/componentSlots.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function initSlots(instance, instanceChildren) {
2+
instance.slots = instanceChildren || [];
3+
}

src/runtime-core/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function addAttrs(vnode, container) {
7272
}
7373

7474
function setupRenderEffect(instance, container, initialVNode) {
75-
const subTree = instance.render.call(instance.proxy);
75+
const subTree = instance?.render.call(instance.proxy);
7676
patch(subTree, container);
7777

7878
initialVNode.el = subTree.el;

0 commit comments

Comments
 (0)