Skip to content

Commit 207c18c

Browse files
committed
further reduce normalizeChildren usage
1 parent 7c3c86f commit 207c18c

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

flow/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ declare interface Component {
7575
propsData: ?Object,
7676
listeners: ?{ [key: string]: Function | Array<Function> },
7777
parentVnode: VNode,
78-
renderChildren: ?VNodeChildren
78+
renderChildren: ?Array<VNode>
7979
) => void;
8080
// rendering
8181
_render: () => VNode;

flow/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare type InternalComponentOptions = {
44
propsData: ?Object;
55
_parentVnode: VNode;
66
_parentListeners: ?Object;
7-
_renderChildren: ?VNodeChildren;
7+
_renderChildren: ?Array<VNode>;
88
_componentTag: ?string;
99
_parentElm: ?Node;
1010
_refElm: ?Node;
@@ -59,7 +59,7 @@ declare type ComponentOptions = {
5959
_propKeys?: Array<string>;
6060
_parentVnode?: VNode;
6161
_parentListeners?: ?Object;
62-
_renderChildren?: ?VNodeChildren;
62+
_renderChildren?: ?Array<VNode>;
6363
_componentTag: ?string;
6464
_scopeId: ?string;
6565
_base: Class<Component>;

flow/vnode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare type VNodeComponentOptions = {
44
Ctor: Class<Component>;
55
propsData: ?Object;
66
listeners: ?Object;
7-
children: ?VNodeChildren;
7+
children: ?Array<VNode>;
88
tag?: string;
99
}
1010

@@ -19,7 +19,7 @@ declare type MountedComponentVNode = {
1919
declare type VNodeWithData = {
2020
tag: string;
2121
data: VNodeData;
22-
children: Array<VNode> | void;
22+
children: ?Array<VNode>;
2323
text: void;
2424
elm: any;
2525
ns: string | void;

src/core/instance/lifecycle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
117117
propsData: ?Object,
118118
listeners: ?Object,
119119
parentVnode: VNode,
120-
renderChildren: ?VNodeChildren
120+
renderChildren: ?Array<VNode>
121121
) {
122122
const vm: Component = this
123123
const hasChildren = !!(vm.$options._renderChildren || renderChildren)

src/core/instance/render.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* @flow */
22

33
import config from '../config'
4-
import { normalizeChildren } from '../vdom/helpers/index'
54
import VNode, {
65
cloneVNode,
76
cloneVNodes,
@@ -34,7 +33,7 @@ export function initRender (vm: Component) {
3433
// bind the createElement fn to this instance
3534
// so that we get proper render context inside it.
3635
// args order: tag, data, children, needNormalization
37-
// the needNormalization flag is flipped and defaults to true for the public version.
36+
// the needNormalization flag is disabled for the public version.
3837
vm._h = (a, b, c, d) => createElement(vm, a, b, c, d, false)
3938
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
4039
if (vm.$options.el) {
@@ -270,14 +269,13 @@ export function renderMixin (Vue: Class<Component>) {
270269
}
271270

272271
export function resolveSlots (
273-
renderChildren: ?VNodeChildren,
272+
children: ?Array<VNode>,
274273
context: ?Component
275274
): { [key: string]: Array<VNode> } {
276275
const slots = {}
277-
if (!renderChildren) {
276+
if (!children) {
278277
return slots
279278
}
280-
const children = normalizeChildren(renderChildren) || []
281279
const defaultSlot = []
282280
let name, child
283281
for (let i = 0, l = children.length; i < l; i++) {

src/core/vdom/create-component.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* @flow */
22

33
import VNode from './vnode'
4-
import { normalizeChildren } from './helpers/index'
54
import { resolveConstructorOptions } from '../instance/init'
65
import { activeInstance, callHook } from '../instance/lifecycle'
76
import { resolveSlots } from '../instance/render'
@@ -15,7 +14,7 @@ export function createComponent (
1514
Ctor: Class<Component> | Function | Object | void,
1615
data?: VNodeData,
1716
context: Component,
18-
children?: VNodeChildren,
17+
children: ?Array<VNode>,
1918
tag?: string
2019
): VNode | void {
2120
if (!Ctor) {
@@ -96,7 +95,7 @@ function createFunctionalComponent (
9695
propsData: ?Object,
9796
data: VNodeData,
9897
context: Component,
99-
children?: VNodeChildren
98+
children: ?Array<VNode>
10099
): VNode | void {
101100
const props = {}
102101
const propOptions = Ctor.options.props
@@ -113,7 +112,7 @@ function createFunctionalComponent (
113112
props,
114113
data,
115114
parent: context,
116-
children: normalizeChildren(children),
115+
children,
117116
slots: () => resolveSlots(children, context)
118117
})
119118
if (vnode instanceof VNode) {

src/core/vdom/create-element.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export function createElement (
1414
data: any,
1515
children: any,
1616
needNormalization: any,
17-
flipNormalization: boolean
17+
alwaysNormalize: boolean
1818
): VNode {
1919
if (Array.isArray(data) || isPrimitive(data)) {
2020
needNormalization = children
2121
children = data
2222
data = undefined
2323
}
24-
if (flipNormalization) needNormalization = !needNormalization
24+
if (alwaysNormalize) needNormalization = true
2525
return _createElement(context, tag, data, children, needNormalization)
2626
}
2727

@@ -51,14 +51,17 @@ export function _createElement (
5151
data.scopedSlots = { default: children[0] }
5252
children.length = 0
5353
}
54+
if (needNormalization) {
55+
children = normalizeChildren(children)
56+
}
5457
let vnode, ns
5558
if (typeof tag === 'string') {
5659
let Ctor
5760
ns = config.getTagNamespace(tag)
5861
if (config.isReservedTag(tag)) {
5962
// platform built-in elements
6063
vnode = new VNode(
61-
tag, data, needNormalization ? normalizeChildren(children) : children,
64+
tag, data, children,
6265
undefined, undefined, context
6366
)
6467
} else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
@@ -70,7 +73,7 @@ export function _createElement (
7073
// parent normalizes children
7174
ns = tag === 'foreignObject' ? 'xhtml' : ns
7275
vnode = new VNode(
73-
tag, data, needNormalization ? normalizeChildren(children) : children,
76+
tag, data, children,
7477
undefined, undefined, context
7578
)
7679
}

src/core/vdom/helpers/normalize-children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { isPrimitive } from 'core/util/index'
44
import VNode, { createTextVNode } from 'core/vdom/vnode'
55

6-
export function normalizeChildren (children: any): Array<VNode> | void {
6+
export function normalizeChildren (children: any): ?Array<VNode> {
77
return isPrimitive(children)
88
? [createTextVNode(children)]
99
: Array.isArray(children)

src/core/vdom/vnode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export default class VNode {
44
tag: string | void;
55
data: VNodeData | void;
6-
children: Array<VNode> | void;
6+
children: ?Array<VNode>;
77
text: string | void;
88
elm: Node | void;
99
ns: string | void;
@@ -23,7 +23,7 @@ export default class VNode {
2323
constructor (
2424
tag?: string,
2525
data?: VNodeData,
26-
children?: Array<VNode> | void,
26+
children?: ?Array<VNode>,
2727
text?: string,
2828
elm?: Node,
2929
context?: Component,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy