| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /* @flow */
- import VNode, { emptyVNode } from './vnode'
- import config from '../config'
- import { createComponent } from './create-component'
- import { normalizeChildren } from './helpers'
- import { warn, resolveAsset } from '../util/index'
- // wrapper function for providing a more flexible interface
- // without getting yelled at by flow
- export function createElement (
- tag: any,
- data: any,
- children: any
- ): VNode | Array<VNode> | void {
- if (data && (Array.isArray(data) || typeof data !== 'object')) {
- children = data
- data = undefined
- }
- // make sure to use real instance instead of proxy as context
- return _createElement(this._self, tag, data, children)
- }
- function _createElement (
- context: Component,
- tag?: string | Class<Component> | Function | Object,
- data?: VNodeData,
- children?: VNodeChildren | void
- ): VNode | Array<VNode> | void {
- if (data && data.__ob__) {
- process.env.NODE_ENV !== 'production' && warn(
- `Avoid using observed data object as vnode data: ${JSON.stringify(data)}\n` +
- 'Always create fresh vnode data objects in each render!',
- context
- )
- return
- }
- if (!tag) {
- // in case of component :is set to falsy value
- return emptyVNode()
- }
- if (typeof tag === 'string') {
- let Ctor
- const ns = config.getTagNamespace(tag)
- if (config.isReservedTag(tag)) {
- // platform built-in elements
- return new VNode(
- tag, data, normalizeChildren(children, ns),
- undefined, undefined, ns, context
- )
- } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
- // component
- return createComponent(Ctor, data, context, children, tag)
- } else {
- // unknown or unlisted namespaced elements
- // check at runtime because it may get assigned a namespace when its
- // parent normalizes children
- return new VNode(
- tag, data, normalizeChildren(children, ns),
- undefined, undefined, ns, context
- )
- }
- } else {
- // direct component options / constructor
- return createComponent(tag, data, context, children)
- }
- }
|