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