]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-core): extract key/ref normalization logic
authorEvan You <yyx990803@gmail.com>
Fri, 24 Apr 2020 16:56:38 +0000 (12:56 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 24 Apr 2020 17:06:56 +0000 (13:06 -0400)
packages/runtime-core/src/vnode.ts

index 3e2bf518e82b54a908a80fe99e6394c163ea755b..f4de40eff1f5f4670cc49ac03deed89e3c501959 100644 (file)
@@ -239,6 +239,16 @@ const createVNodeWithArgsTransform = (
 
 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__
   ? createVNodeWithArgsTransform
   : _createVNode) as typeof _createVNode
@@ -312,11 +322,8 @@ function _createVNode(
     _isVNode: true,
     type,
     props,
-    key: props && props.key != null ? props.key : null,
-    ref:
-      props && props.ref != null
-        ? [currentRenderingInstance!, props.ref]
-        : null,
+    key: props && normalizeKey(props),
+    ref: props && normalizeRef(props),
     scopeId: currentScopeId,
     children: null,
     component: null,
@@ -373,13 +380,8 @@ export function cloneVNode<T, U>(
     _isVNode: true,
     type: vnode.type,
     props,
-    key: props && props.key != null ? props.key : null,
-    ref:
-      props && props.ref != null
-        ? isArray(props.ref)
-          ? props.ref
-          : [currentRenderingInstance!, props.ref]
-        : null,
+    key: props && normalizeKey(props),
+    ref: props && normalizeRef(props),
     scopeId: vnode.scopeId,
     children: vnode.children,
     target: vnode.target,