-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg.main
78 lines (71 loc) · 1.79 KB
/
pkg.main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function createComponentInstance(vnode) {
const component = {
vnode,
type: vnode.type,
};
return component;
}
function setupComponent(instance) {
setupStatefulComponent(instance);
}
function setupStatefulComponent(instance) {
const component = instance.type;
const { setup } = component;
if (setup) {
const setupResult = setup();
handleSetupResult(instance, setupResult);
}
}
function handleSetupResult(instance, setupResult) {
if (typeof setupResult === "object") {
instance.setupState = setupResult;
}
finishComponentSetup(instance);
}
function finishComponentSetup(instance) {
const Component = instance.type;
instance.render = Component.render;
}
function render(vnode, container) {
patch(vnode);
}
function patch(vnode, container) {
// TODO 判断 vnode 是不是一个element
// 是 element 就处理 element
processComponent(vnode);
}
function processComponent(vnode, container) {
mountComponent(vnode);
}
function mountComponent(vnode, container) {
const instance = createComponentInstance(vnode);
setupComponent(instance);
setupRenderEffect(instance);
}
function setupRenderEffect(instance, container) {
const subTree = instance.render();
patch(subTree);
}
function createVNode(type, props, children) {
const vnode = {
type,
props,
children,
};
return vnode;
}
function createApp(rootComponent) {
return {
mount(rootContainer) {
const vnode = createVNode(rootComponent);
render(vnode);
},
};
}
function h(type, props, children) {
return createVNode(type, props, children);
}
exports.createApp = createApp;
exports.h = h;