@@ -4,6 +4,7 @@ import VNode from './vnode'
44import { createElement } from './create-element'
55import { resolveInject } from '../instance/inject'
66import { resolveSlots } from '../instance/render-helpers/resolve-slots'
7+ import { installRenderHelpers } from '../instance/render-helpers/index'
78
89import {
910 isDef ,
@@ -12,15 +13,43 @@ import {
1213 validateProp
1314} from '../util/index'
1415
16+ function FunctionalRenderContext (
17+ data ,
18+ props ,
19+ children ,
20+ parent ,
21+ Ctor
22+ ) {
23+ const options = Ctor . options
24+ this . data = data
25+ this . props = props
26+ this . children = children
27+ this . parent = parent
28+ this . listeners = data . on || emptyObject
29+ this . injections = resolveInject ( options . inject , parent )
30+ this . slots = ( ) => resolveSlots ( children , parent )
31+ // support for compiled functional template
32+ if ( options . _compiled ) {
33+ this . constructor = Ctor
34+ this . $options = options
35+ this . _c = parent . _c
36+ this . $slots = this . slots ( )
37+ this . $scopedSlots = data . scopedSlots || emptyObject
38+ }
39+ }
40+
41+ installRenderHelpers ( FunctionalRenderContext . prototype )
42+
1543export function createFunctionalComponent (
1644 Ctor : Class < Component > ,
1745 propsData : ?Object ,
1846 data : VNodeData ,
19- context : Component ,
47+ contextVm : Component ,
2048 children : ?Array < VNode >
2149) : VNode | void {
50+ const options = Ctor . options
2251 const props = { }
23- const propOptions = Ctor . options . props
52+ const propOptions = options . props
2453 if ( isDef ( propOptions ) ) {
2554 for ( const key in propOptions ) {
2655 props [ key ] = validateProp ( key , propOptions , propsData || emptyObject )
@@ -31,20 +60,19 @@ export function createFunctionalComponent (
3160 }
3261 // ensure the createElement function in functional components
3362 // gets a unique context - this is necessary for correct named slot check
34- const _context = Object . create ( context )
35- const h = ( a , b , c , d ) => createElement ( _context , a , b , c , d , true )
36- const vnode = Ctor . options . render . call ( null , h , {
63+ const _contextVm = Object . create ( contextVm )
64+ const h = ( a , b , c , d ) => createElement ( _contextVm , a , b , c , d , true )
65+ const renderContext = new FunctionalRenderContext (
3766 data ,
3867 props ,
3968 children ,
40- parent : context ,
41- listeners : data . on || emptyObject ,
42- injections : resolveInject ( Ctor . options . inject , context ) ,
43- slots : ( ) => resolveSlots ( children , context )
44- } )
69+ contextVm ,
70+ Ctor
71+ )
72+ const vnode = options . render . call ( null , h , renderContext )
4573 if ( vnode instanceof VNode ) {
46- vnode . functionalContext = context
47- vnode . functionalOptions = Ctor . options
74+ vnode . functionalContext = contextVm
75+ vnode . functionalOptions = options
4876 if ( data . slot ) {
4977 ( vnode . data || ( vnode . data = { } ) ) . slot = data . slot
5078 }
0 commit comments