diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-04 11:50:26 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-04 11:50:26 +0200 |
commit | 30b577138dda685f65a8529be1866afa6e321845 (patch) | |
tree | bfa92ee3ab485a6b11f86731777ecf5c5d166bab /src/vdom/functional-component.js |
Squashed 'thirdparty/preact/' content from commit b2d90cc
git-subtree-dir: thirdparty/preact
git-subtree-split: b2d90cc116f1d1998f7a7c98dc6986bf4c1841f4
Diffstat (limited to 'src/vdom/functional-component.js')
-rw-r--r-- | src/vdom/functional-component.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vdom/functional-component.js b/src/vdom/functional-component.js new file mode 100644 index 000000000..04bc5a464 --- /dev/null +++ b/src/vdom/functional-component.js @@ -0,0 +1,25 @@ +import { EMPTY } from '../constants'; +import { getNodeProps } from './index'; +import { isFunction } from '../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 + */ +export function isFunctionalComponent(vnode) { + let nodeName = vnode && vnode.nodeName; + return nodeName && 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 + */ +export function buildFunctionalComponent(vnode, context) { + return vnode.nodeName(getNodeProps(vnode), context || EMPTY); +} |