MCPcopy Index your code
hub / github.com/ygs-code/vue / resolveSlots

Function resolveSlots

vue.js:3788–3841  ·  view source on GitHub ↗

* Runtime helper for resolving raw children VNodes into a slot object. * 用于将原始子节点vnode解析为槽对象的运行时帮助器。 * * 判断children 有没有分发式插槽 并且过滤掉空的插槽,并且收集插槽 *

(children,
        context)

Source from the content-addressed store, hash-verified

3786 *
3787 */
3788 function resolveSlots(children,
3789 context) {
3790 var slots = {};
3791 //如果没有子节点 则返回一个空对象
3792 if (!children) {
3793 return slots
3794 }
3795 //循环子节点
3796 for (var i = 0, l = children.length; i < l; i++) {
3797 //获取单个子节点
3798 var child = children[i];
3799 //获取子节点数据
3800 var data = child.data;
3801 // remove slot attribute if the node is resolved as a Vue slot node
3802 //如果节点被解析为Vue槽节点,则删除slot属性 slot 分发式属性
3803 if (data && data.attrs && data.attrs.slot) {
3804 delete data.attrs.slot;
3805 }
3806 //只有在
3807 // named slots should only be respected if the vnode was rendered in the
3808 //如果在VN节点中呈现VNT,则只应命名命名槽。
3809
3810 // same context.
3811 //同样的背景。
3812 //context 上下文
3813 if ((child.context === context || child.fnContext === context) &&
3814 data && data.slot != null
3815 ) {
3816 //如果有内容分发 插槽
3817 var name = data.slot;
3818 var slot = (slots[name] || (slots[name] = []));
3819 //child 有模板
3820 if (child.tag === 'template') {
3821 //把子节点的 子节点 添加 到slot插槽中
3822 slot.push.apply(slot, child.children || []);
3823 } else {
3824 //把子节点 添加 到slot插槽中
3825 slot.push(child);
3826 }
3827 } else {
3828 //
3829 (slots.default || (slots.default = [])).push(child);
3830 }
3831 }
3832 // ignore slots that contains only whitespace
3833 //忽略只包含空白的槽
3834 for (var name$1 in slots) {
3835 //删除空的插槽
3836 if (slots[name$1].every(isWhitespace)) {
3837 delete slots[name$1];
3838 }
3839 }
3840 return slots
3841 }
3842
3843 function isWhitespace(node) {
3844 //不是异步

Callers 3

updateChildComponentFunction · 0.85
FunctionalRenderContextFunction · 0.85
initRenderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected