mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 11:07:51 +08:00
further reduce normalizeChildren usage
This commit is contained in:
parent
7c3c86f360
commit
207c18c47f
@ -75,7 +75,7 @@ declare interface Component {
|
||||
propsData: ?Object,
|
||||
listeners: ?{ [key: string]: Function | Array<Function> },
|
||||
parentVnode: VNode,
|
||||
renderChildren: ?VNodeChildren
|
||||
renderChildren: ?Array<VNode>
|
||||
) => void;
|
||||
// rendering
|
||||
_render: () => VNode;
|
||||
|
@ -4,7 +4,7 @@ declare type InternalComponentOptions = {
|
||||
propsData: ?Object;
|
||||
_parentVnode: VNode;
|
||||
_parentListeners: ?Object;
|
||||
_renderChildren: ?VNodeChildren;
|
||||
_renderChildren: ?Array<VNode>;
|
||||
_componentTag: ?string;
|
||||
_parentElm: ?Node;
|
||||
_refElm: ?Node;
|
||||
@ -59,7 +59,7 @@ declare type ComponentOptions = {
|
||||
_propKeys?: Array<string>;
|
||||
_parentVnode?: VNode;
|
||||
_parentListeners?: ?Object;
|
||||
_renderChildren?: ?VNodeChildren;
|
||||
_renderChildren?: ?Array<VNode>;
|
||||
_componentTag: ?string;
|
||||
_scopeId: ?string;
|
||||
_base: Class<Component>;
|
||||
|
@ -4,7 +4,7 @@ declare type VNodeComponentOptions = {
|
||||
Ctor: Class<Component>;
|
||||
propsData: ?Object;
|
||||
listeners: ?Object;
|
||||
children: ?VNodeChildren;
|
||||
children: ?Array<VNode>;
|
||||
tag?: string;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ declare type MountedComponentVNode = {
|
||||
declare type VNodeWithData = {
|
||||
tag: string;
|
||||
data: VNodeData;
|
||||
children: Array<VNode> | void;
|
||||
children: ?Array<VNode>;
|
||||
text: void;
|
||||
elm: any;
|
||||
ns: string | void;
|
||||
|
@ -117,7 +117,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
|
||||
propsData: ?Object,
|
||||
listeners: ?Object,
|
||||
parentVnode: VNode,
|
||||
renderChildren: ?VNodeChildren
|
||||
renderChildren: ?Array<VNode>
|
||||
) {
|
||||
const vm: Component = this
|
||||
const hasChildren = !!(vm.$options._renderChildren || renderChildren)
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* @flow */
|
||||
|
||||
import config from '../config'
|
||||
import { normalizeChildren } from '../vdom/helpers/index'
|
||||
import VNode, {
|
||||
cloneVNode,
|
||||
cloneVNodes,
|
||||
@ -34,7 +33,7 @@ export function initRender (vm: Component) {
|
||||
// bind the createElement fn to this instance
|
||||
// so that we get proper render context inside it.
|
||||
// args order: tag, data, children, needNormalization
|
||||
// the needNormalization flag is flipped and defaults to true for the public version.
|
||||
// the needNormalization flag is disabled for the public version.
|
||||
vm._h = (a, b, c, d) => createElement(vm, a, b, c, d, false)
|
||||
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
|
||||
if (vm.$options.el) {
|
||||
@ -270,14 +269,13 @@ export function renderMixin (Vue: Class<Component>) {
|
||||
}
|
||||
|
||||
export function resolveSlots (
|
||||
renderChildren: ?VNodeChildren,
|
||||
children: ?Array<VNode>,
|
||||
context: ?Component
|
||||
): { [key: string]: Array<VNode> } {
|
||||
const slots = {}
|
||||
if (!renderChildren) {
|
||||
if (!children) {
|
||||
return slots
|
||||
}
|
||||
const children = normalizeChildren(renderChildren) || []
|
||||
const defaultSlot = []
|
||||
let name, child
|
||||
for (let i = 0, l = children.length; i < l; i++) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* @flow */
|
||||
|
||||
import VNode from './vnode'
|
||||
import { normalizeChildren } from './helpers/index'
|
||||
import { resolveConstructorOptions } from '../instance/init'
|
||||
import { activeInstance, callHook } from '../instance/lifecycle'
|
||||
import { resolveSlots } from '../instance/render'
|
||||
@ -15,7 +14,7 @@ export function createComponent (
|
||||
Ctor: Class<Component> | Function | Object | void,
|
||||
data?: VNodeData,
|
||||
context: Component,
|
||||
children?: VNodeChildren,
|
||||
children: ?Array<VNode>,
|
||||
tag?: string
|
||||
): VNode | void {
|
||||
if (!Ctor) {
|
||||
@ -96,7 +95,7 @@ function createFunctionalComponent (
|
||||
propsData: ?Object,
|
||||
data: VNodeData,
|
||||
context: Component,
|
||||
children?: VNodeChildren
|
||||
children: ?Array<VNode>
|
||||
): VNode | void {
|
||||
const props = {}
|
||||
const propOptions = Ctor.options.props
|
||||
@ -113,7 +112,7 @@ function createFunctionalComponent (
|
||||
props,
|
||||
data,
|
||||
parent: context,
|
||||
children: normalizeChildren(children),
|
||||
children,
|
||||
slots: () => resolveSlots(children, context)
|
||||
})
|
||||
if (vnode instanceof VNode) {
|
||||
|
@ -14,14 +14,14 @@ export function createElement (
|
||||
data: any,
|
||||
children: any,
|
||||
needNormalization: any,
|
||||
flipNormalization: boolean
|
||||
alwaysNormalize: boolean
|
||||
): VNode {
|
||||
if (Array.isArray(data) || isPrimitive(data)) {
|
||||
needNormalization = children
|
||||
children = data
|
||||
data = undefined
|
||||
}
|
||||
if (flipNormalization) needNormalization = !needNormalization
|
||||
if (alwaysNormalize) needNormalization = true
|
||||
return _createElement(context, tag, data, children, needNormalization)
|
||||
}
|
||||
|
||||
@ -51,6 +51,9 @@ export function _createElement (
|
||||
data.scopedSlots = { default: children[0] }
|
||||
children.length = 0
|
||||
}
|
||||
if (needNormalization) {
|
||||
children = normalizeChildren(children)
|
||||
}
|
||||
let vnode, ns
|
||||
if (typeof tag === 'string') {
|
||||
let Ctor
|
||||
@ -58,7 +61,7 @@ export function _createElement (
|
||||
if (config.isReservedTag(tag)) {
|
||||
// platform built-in elements
|
||||
vnode = new VNode(
|
||||
tag, data, needNormalization ? normalizeChildren(children) : children,
|
||||
tag, data, children,
|
||||
undefined, undefined, context
|
||||
)
|
||||
} else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
|
||||
@ -70,7 +73,7 @@ export function _createElement (
|
||||
// parent normalizes children
|
||||
ns = tag === 'foreignObject' ? 'xhtml' : ns
|
||||
vnode = new VNode(
|
||||
tag, data, needNormalization ? normalizeChildren(children) : children,
|
||||
tag, data, children,
|
||||
undefined, undefined, context
|
||||
)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
import { isPrimitive } from 'core/util/index'
|
||||
import VNode, { createTextVNode } from 'core/vdom/vnode'
|
||||
|
||||
export function normalizeChildren (children: any): Array<VNode> | void {
|
||||
export function normalizeChildren (children: any): ?Array<VNode> {
|
||||
return isPrimitive(children)
|
||||
? [createTextVNode(children)]
|
||||
: Array.isArray(children)
|
||||
|
@ -3,7 +3,7 @@
|
||||
export default class VNode {
|
||||
tag: string | void;
|
||||
data: VNodeData | void;
|
||||
children: Array<VNode> | void;
|
||||
children: ?Array<VNode>;
|
||||
text: string | void;
|
||||
elm: Node | void;
|
||||
ns: string | void;
|
||||
@ -23,7 +23,7 @@ export default class VNode {
|
||||
constructor (
|
||||
tag?: string,
|
||||
data?: VNodeData,
|
||||
children?: Array<VNode> | void,
|
||||
children?: ?Array<VNode>,
|
||||
text?: string,
|
||||
elm?: Node,
|
||||
context?: Component,
|
||||
|
Loading…
Reference in New Issue
Block a user