UNPKG

997 BJavaScriptView Raw
1import { EMPTY } from '../constants';
2import { getNodeProps } from './index';
3import { isFunction } from '../util';
4
5
6/** Check if a VNode is a reference to a stateless functional component.
7 * A function component is represented as a VNode whose `nodeName` property is a reference to a function.
8 * If that function is not a Component (ie, has no `.render()` method on a prototype), it is considered a stateless functional component.
9 * @param {VNode} vnode A VNode
10 * @private
11 */
12export function isFunctionalComponent(vnode) {
13 let nodeName = vnode && vnode.nodeName;
14 return nodeName && isFunction(nodeName) && !(nodeName.prototype && nodeName.prototype.render);
15}
16
17
18
19/** Construct a resultant VNode from a VNode referencing a stateless functional component.
20 * @param {VNode} vnode A VNode with a `nodeName` property that is a reference to a function.
21 * @private
22 */
23export function buildFunctionalComponent(vnode, context) {
24 return vnode.nodeName(getNodeProps(vnode), context || EMPTY);
25}