UNPKG

1.05 kBJavaScriptView Raw
1/* @flow */
2
3import { extend, warn, isObject } from 'core/util/index'
4
5/**
6 * Runtime helper for rendering <slot>
7 */
8export function renderSlot (
9 name: string,
10 fallbackRender: ?((() => Array<VNode>) | Array<VNode>),
11 props: ?Object,
12 bindObject: ?Object
13): ?Array<VNode> {
14 const scopedSlotFn = this.$scopedSlots[name]
15 let nodes
16 if (scopedSlotFn) {
17 // scoped slot
18 props = props || {}
19 if (bindObject) {
20 if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
21 warn('slot v-bind without argument expects an Object', this)
22 }
23 props = extend(extend({}, bindObject), props)
24 }
25 nodes =
26 scopedSlotFn(props) ||
27 (typeof fallbackRender === 'function' ? fallbackRender() : fallbackRender)
28 } else {
29 nodes =
30 this.$slots[name] ||
31 (typeof fallbackRender === 'function' ? fallbackRender() : fallbackRender)
32 }
33
34 const target = props && props.slot
35 if (target) {
36 return this.$createElement('template', { slot: target }, nodes)
37 } else {
38 return nodes
39 }
40}