Skip to content

Commit

Permalink
feat(functional): Support components hash in functional components
Browse files Browse the repository at this point in the history
Adds support for the components hash to be used in functional components

fix vuejs#7492
  • Loading branch information
Hiroki Osame committed May 7, 2018
1 parent 07e264a commit 345713e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/vdom/create-functional-component.js
Expand Up @@ -6,6 +6,7 @@ import { resolveInject } from '../instance/inject'
import { normalizeChildren } from '../vdom/helpers/normalize-children'
import { resolveSlots } from '../instance/render-helpers/resolve-slots'
import { installRenderHelpers } from '../instance/render-helpers/index'
import { extend } from 'shared/util'

import {
isDef,
Expand Down Expand Up @@ -39,6 +40,10 @@ export function FunctionalRenderContext (
// $flow-disable-line
parent = parent._original
}

contextVm.$options = Object.create(contextVm.$options)
contextVm.$options.components = extend(Object.create(contextVm.$options.components), options.components)

const isCompiled = isTrue(options._compiled)
const needNormalization = !isCompiled

Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/options/functional.spec.js
Expand Up @@ -242,6 +242,34 @@ describe('Options functional', () => {
expect(vm.$el.childNodes[1].namespaceURI).toContain('svg')
})

it('should accept components', () => {
const HelloComp = {
template: `<div>Hello</div>`
}

const WorldComp = {
template: `<div>World</div>`
}

const Child = {
functional: true,
components: {
HelloComp
},
render: h => [h('hello-comp'), h('world-comp')]
}

const vm = new Vue({
template: `<div><child/></div>`,
components: {
Child,
WorldComp
}
}).$mount()

expect(vm.$el.innerHTML).toBe('<div>Hello</div><div>World</div>')
})

it('should work with render fns compiled from template', done => {
// code generated via vue-template-es2015-compiler
var render = function (_h, _vm) {
Expand Down

0 comments on commit 345713e

Please sign in to comment.