-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0a9c16
commit 955689d
Showing
10 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @flow | ||
|
||
import Vue from 'vue' | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
|
||
const _renderSlot = Vue.prototype._t | ||
|
||
function createVNodes ( | ||
vm: Component, | ||
slotValue: Component | string | ||
): ?Array<VNode> { | ||
if (typeof slotValue === 'string') { | ||
const compiledResult = compileToFunctions(`<div>${slotValue}{{ }}</div>`) | ||
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns | ||
vm._renderProxy.$options.staticRenderFns = compiledResult.staticRenderFns | ||
const vnodes = compiledResult.render.call( | ||
vm._renderProxy, vm.$createElement | ||
).children | ||
vm._renderProxy.$options.staticRenderFns = _staticRenderFns | ||
return vnodes | ||
} | ||
return [vm.$createElement(slotValue)] | ||
} | ||
|
||
export default function createRenderSlot ( | ||
options: Object | ||
): ( | ||
name: string, | ||
fallback: ?Array<VNode>, | ||
props: ?Object, | ||
bindObject: ?Object | ||
) => ?Array<VNode> { | ||
return function renderSlot ( | ||
name: string, | ||
fallback: ?Array<VNode>, | ||
props: ?Object, | ||
bindObject: ?Object | ||
): ?Array<VNode> { | ||
if (options.slots && options.slots[name]) { | ||
this.$slots[name] = [] | ||
const slotsValue = options.slots[name] | ||
if (Array.isArray(slotsValue)) { | ||
slotsValue.forEach((value) => { | ||
if (typeof value === 'string') { | ||
const slots = createVNodes(this, value) | ||
if (Array.isArray(slots)) { | ||
this.$slots[name].push(...slots) | ||
} | ||
} else { | ||
this.$slots[name].push(this.$createElement(value)) | ||
} | ||
}) | ||
} else { | ||
const slots = createVNodes(this, slotsValue) | ||
if (Array.isArray(slots)) { | ||
this.$slots[name] = slots | ||
} | ||
} | ||
} | ||
return _renderSlot.call(this, name, fallback, props, bindObject) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @flow | ||
|
||
import createInstance from './create-instance' | ||
import createRenderSlot from './create-render-slot' | ||
|
||
export { createInstance, createRenderSlot } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "create-instance", | ||
"version": "1.0.0-beta.20", | ||
"main": "create-instance.js", | ||
"main": "index.js", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
i<template> | ||
<div foo="bar"><span baz="qux">{{ quux }}</span></div> | ||
</template> | ||
|
||
<script> | ||
export default{ | ||
name: 'component-with-parent-name', | ||
data () { | ||
return { | ||
quux: 'quux' | ||
} | ||
}, | ||
mounted () { | ||
this.$parent.childName = this.$options.name | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters