all files / src/vdom/ functional-component.js

100% Statements 11/11
90.91% Branches 10/11
100% Functions 2/2
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33    12× 12× 12×   12×   12×   12×                 30004× 30004×               45×    
'use strict';
 
exports.__esModule = true;
exports.isFunctionalComponent = isFunctionalComponent;
exports.buildFunctionalComponent = buildFunctionalComponent;
 
var _constants = require('../constants');
 
var _index = require('./index');
 
var _util = require('../util');
 
/** Check if a VNode is a reference to a stateless functional component.
 *	A function component is represented as a VNode whose `nodeName` property is a reference to a function.
 *	If that function is not a Component (ie, has no `.render()` method on a prototype), it is considered a stateless functional component.
 *	@param {VNode} vnode	A VNode
 *	@private
 */
 
function isFunctionalComponent(vnode) {
  var nodeName = vnode && vnode.nodeName;
  return nodeName && _util.isFunction(nodeName) && !(nodeName.prototype && nodeName.prototype.render);
}
 
/** Construct a resultant VNode from a VNode referencing a stateless functional component.
 *	@param {VNode} vnode	A VNode with a `nodeName` property that is a reference to a function.
 *	@private
 */
 
function buildFunctionalComponent(vnode, context) {
  return vnode.nodeName(_index.getNodeProps(vnode), context || _constants.EMPTY) || _constants.EMPTY_BASE;
}