wip: optimize children shapeFlag
This commit is contained in:
parent
6d90ba28d3
commit
1681787b43
@ -10,7 +10,7 @@ import { RenderProxyHandlers } from './componentProxy'
|
||||
import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
|
||||
import { PROPS, DYNAMIC_SLOTS, FULL_PROPS } from './patchFlags'
|
||||
import { Slots } from './componentSlots'
|
||||
import { STATEFUL_COMPONENT } from './shapeFlags'
|
||||
import { STATEFUL_COMPONENT } from './typeFlags'
|
||||
|
||||
export type Data = { [key: string]: any }
|
||||
|
||||
|
@ -34,7 +34,7 @@ import {
|
||||
FUNCTIONAL_COMPONENT,
|
||||
TEXT_CHILDREN,
|
||||
ARRAY_CHILDREN
|
||||
} from './shapeFlags'
|
||||
} from './typeFlags'
|
||||
|
||||
const prodEffectOptions = {
|
||||
scheduler: queueJob
|
||||
|
@ -9,14 +9,12 @@ export {
|
||||
Portal
|
||||
} from './vnode'
|
||||
|
||||
export { FunctionalComponent, createComponent } from './component'
|
||||
|
||||
export { createComponent, FunctionalComponent } from './component'
|
||||
export { createRenderer, RendererOptions } from './createRenderer'
|
||||
export { Slot, Slots } from './componentSlots'
|
||||
|
||||
export { PropType, ComponentPropsOptions } from './componentProps'
|
||||
|
||||
export * from './reactivity'
|
||||
export * from './componentLifecycle'
|
||||
export { createRenderer, RendererOptions } from './createRenderer'
|
||||
|
||||
export { TEXT, CLASS, STYLE, PROPS, KEYED, UNKEYED } from './patchFlags'
|
||||
export * from './patchFlags'
|
||||
export * from './typeFlags'
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
TEXT_CHILDREN,
|
||||
ARRAY_CHILDREN,
|
||||
SLOTS_CHILDREN
|
||||
} from './shapeFlags'
|
||||
} from './typeFlags'
|
||||
|
||||
export const Fragment = Symbol('Fragment')
|
||||
export const Text = Symbol('Text')
|
||||
@ -102,40 +102,33 @@ export function createVNode(
|
||||
): VNode {
|
||||
// Allow passing 0 for props, this can save bytes on generated code.
|
||||
props = props || null
|
||||
// normalize children
|
||||
children = normalizeChildren(children) as NormalizedChildren
|
||||
|
||||
// encode the vnode type information into a bitmap
|
||||
const typeFlag = isString(type)
|
||||
? ELEMENT
|
||||
: isFunction(type)
|
||||
? FUNCTIONAL_COMPONENT
|
||||
: isObject(type)
|
||||
? STATEFUL_COMPONENT
|
||||
: 0
|
||||
|
||||
const childFlag = isString(children)
|
||||
? TEXT_CHILDREN
|
||||
: isArray(children)
|
||||
? ARRAY_CHILDREN
|
||||
: isObject(children)
|
||||
? SLOTS_CHILDREN
|
||||
: isFunction(type)
|
||||
? FUNCTIONAL_COMPONENT
|
||||
: 0
|
||||
|
||||
const vnode: VNode = {
|
||||
type,
|
||||
props,
|
||||
key: props && props.key,
|
||||
children,
|
||||
children: null,
|
||||
component: null,
|
||||
el: null,
|
||||
anchor: null,
|
||||
target: null,
|
||||
shapeFlag: typeFlag | childFlag,
|
||||
shapeFlag: typeFlag,
|
||||
patchFlag,
|
||||
dynamicProps,
|
||||
dynamicChildren: null
|
||||
}
|
||||
|
||||
normalizeChildren(vnode, children)
|
||||
|
||||
// class & style normalization.
|
||||
if (props !== null) {
|
||||
// class normalization only needed if the vnode isn't generated by
|
||||
@ -193,18 +186,23 @@ export function normalizeVNode(child: VNodeChild): VNode {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeChildren(children: unknown): NormalizedChildren {
|
||||
export function normalizeChildren(vnode: VNode, children: unknown) {
|
||||
let type = 0
|
||||
if (children == null) {
|
||||
return null
|
||||
children = null
|
||||
} else if (isArray(children)) {
|
||||
return children
|
||||
type = ARRAY_CHILDREN
|
||||
} else if (typeof children === 'object') {
|
||||
return children as RawSlots
|
||||
type = SLOTS_CHILDREN
|
||||
} else if (isFunction(children)) {
|
||||
return { default: children }
|
||||
children = { default: children }
|
||||
type = SLOTS_CHILDREN
|
||||
} else {
|
||||
return isString(children) ? children : children + ''
|
||||
children = isString(children) ? children : children + ''
|
||||
type = TEXT_CHILDREN
|
||||
}
|
||||
vnode.children = children as NormalizedChildren
|
||||
vnode.shapeFlag |= type
|
||||
}
|
||||
|
||||
function normalizeStyle(
|
||||
|
Loading…
Reference in New Issue
Block a user