Skip to content

Commit 4a3000f

Browse files
author
lishiwen
committed
added slots build
1 parent 6a0a1f8 commit 4a3000f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lib/m-vue.cjs.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,10 @@ function emit(instance, eventProperty, ...args) {
160160
}
161161
// TODO: 运行时扩展实例
162162
function extendRuntimeInstance(instance, extendApis = {}) {
163-
console.log("extendApis", extendApis);
164163
// XXX: 临时解决方案
165164
// TODO: 待完善扩展实例
166165
Object.keys(extendApis).forEach(key => {
167166
instance[key] = extendApis[key];
168-
console.log(key, extendApis[key]);
169167
});
170168
}
171169

@@ -174,7 +172,8 @@ function initProps(instance, rawProps = {}) {
174172
}
175173

176174
const PublicPropertiesMaps = {
177-
"$el": (instance) => instance.vnode.el,
175+
$el: (instance) => instance.vnode.el,
176+
$slots: (instance) => instance.slots,
178177
};
179178
const ComponentPublicInstanceHandlers = {
180179
get({ _instance }, key) {
@@ -191,6 +190,10 @@ const ComponentPublicInstanceHandlers = {
191190
}
192191
};
193192

193+
function initSlots(instance, instanceChildren) {
194+
instance.slots = instanceChildren || [];
195+
}
196+
194197
function promiseEmit() { }
195198

196199
var instanceRuntimeExtendApis = /*#__PURE__*/Object.freeze({
@@ -205,6 +208,7 @@ function createComponentInstance(vnode) {
205208
type: vnode.type,
206209
setupState: {},
207210
props: {},
211+
slots: {},
208212
emit: (instance, event) => { },
209213
};
210214
// 官方Emit
@@ -216,7 +220,7 @@ function createComponentInstance(vnode) {
216220
}
217221
function setupComponent(instance) {
218222
initProps(instance, instance.vnode.props);
219-
// initSlots();
223+
initSlots(instance, instance.vnode.children);
220224
setupStatefulComponent(instance);
221225
}
222226
function setupStatefulComponent(instance) {
@@ -306,7 +310,7 @@ function addAttrs(vnode, container) {
306310
}
307311
}
308312
function setupRenderEffect(instance, container, initialVNode) {
309-
const subTree = instance.render.call(instance.proxy);
313+
const subTree = instance === null || instance === void 0 ? void 0 : instance.render.call(instance.proxy);
310314
patch(subTree, container);
311315
initialVNode.el = subTree.el;
312316
}

lib/m-vue.esm.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,10 @@ function emit(instance, eventProperty, ...args) {
156156
}
157157
// TODO: 运行时扩展实例
158158
function extendRuntimeInstance(instance, extendApis = {}) {
159-
console.log("extendApis", extendApis);
160159
// XXX: 临时解决方案
161160
// TODO: 待完善扩展实例
162161
Object.keys(extendApis).forEach(key => {
163162
instance[key] = extendApis[key];
164-
console.log(key, extendApis[key]);
165163
});
166164
}
167165

@@ -170,7 +168,8 @@ function initProps(instance, rawProps = {}) {
170168
}
171169

172170
const PublicPropertiesMaps = {
173-
"$el": (instance) => instance.vnode.el,
171+
$el: (instance) => instance.vnode.el,
172+
$slots: (instance) => instance.slots,
174173
};
175174
const ComponentPublicInstanceHandlers = {
176175
get({ _instance }, key) {
@@ -187,6 +186,10 @@ const ComponentPublicInstanceHandlers = {
187186
}
188187
};
189188

189+
function initSlots(instance, instanceChildren) {
190+
instance.slots = instanceChildren || [];
191+
}
192+
190193
function promiseEmit() { }
191194

192195
var instanceRuntimeExtendApis = /*#__PURE__*/Object.freeze({
@@ -201,6 +204,7 @@ function createComponentInstance(vnode) {
201204
type: vnode.type,
202205
setupState: {},
203206
props: {},
207+
slots: {},
204208
emit: (instance, event) => { },
205209
};
206210
// 官方Emit
@@ -212,7 +216,7 @@ function createComponentInstance(vnode) {
212216
}
213217
function setupComponent(instance) {
214218
initProps(instance, instance.vnode.props);
215-
// initSlots();
219+
initSlots(instance, instance.vnode.children);
216220
setupStatefulComponent(instance);
217221
}
218222
function setupStatefulComponent(instance) {
@@ -302,7 +306,7 @@ function addAttrs(vnode, container) {
302306
}
303307
}
304308
function setupRenderEffect(instance, container, initialVNode) {
305-
const subTree = instance.render.call(instance.proxy);
309+
const subTree = instance === null || instance === void 0 ? void 0 : instance.render.call(instance.proxy);
306310
patch(subTree, container);
307311
initialVNode.el = subTree.el;
308312
}

0 commit comments

Comments
 (0)