refactor(runtime-core): extract key/ref normalization logic
This commit is contained in:
parent
ad2b940c17
commit
c9f10be9de
@ -239,6 +239,16 @@ const createVNodeWithArgsTransform = (
|
|||||||
|
|
||||||
export const InternalObjectKey = `__vInternal`
|
export const InternalObjectKey = `__vInternal`
|
||||||
|
|
||||||
|
const normalizeKey = ({ key }: VNodeProps): VNode['key'] =>
|
||||||
|
key != null ? key : null
|
||||||
|
|
||||||
|
const normalizeRef = ({ ref }: VNodeProps): VNode['ref'] =>
|
||||||
|
(ref != null
|
||||||
|
? isArray(ref)
|
||||||
|
? ref
|
||||||
|
: [currentRenderingInstance!, ref]
|
||||||
|
: null) as any
|
||||||
|
|
||||||
export const createVNode = (__DEV__
|
export const createVNode = (__DEV__
|
||||||
? createVNodeWithArgsTransform
|
? createVNodeWithArgsTransform
|
||||||
: _createVNode) as typeof _createVNode
|
: _createVNode) as typeof _createVNode
|
||||||
@ -312,11 +322,8 @@ function _createVNode(
|
|||||||
_isVNode: true,
|
_isVNode: true,
|
||||||
type,
|
type,
|
||||||
props,
|
props,
|
||||||
key: props && props.key != null ? props.key : null,
|
key: props && normalizeKey(props),
|
||||||
ref:
|
ref: props && normalizeRef(props),
|
||||||
props && props.ref != null
|
|
||||||
? [currentRenderingInstance!, props.ref]
|
|
||||||
: null,
|
|
||||||
scopeId: currentScopeId,
|
scopeId: currentScopeId,
|
||||||
children: null,
|
children: null,
|
||||||
component: null,
|
component: null,
|
||||||
@ -373,13 +380,8 @@ export function cloneVNode<T, U>(
|
|||||||
_isVNode: true,
|
_isVNode: true,
|
||||||
type: vnode.type,
|
type: vnode.type,
|
||||||
props,
|
props,
|
||||||
key: props && props.key != null ? props.key : null,
|
key: props && normalizeKey(props),
|
||||||
ref:
|
ref: props && normalizeRef(props),
|
||||||
props && props.ref != null
|
|
||||||
? isArray(props.ref)
|
|
||||||
? props.ref
|
|
||||||
: [currentRenderingInstance!, props.ref]
|
|
||||||
: null,
|
|
||||||
scopeId: vnode.scopeId,
|
scopeId: vnode.scopeId,
|
||||||
children: vnode.children,
|
children: vnode.children,
|
||||||
target: vnode.target,
|
target: vnode.target,
|
||||||
|
Loading…
Reference in New Issue
Block a user