]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: optimize children shapeFlag
authorEvan You <yyx990803@gmail.com>
Sun, 2 Jun 2019 14:22:44 +0000 (22:22 +0800)
committerEvan You <yyx990803@gmail.com>
Sun, 2 Jun 2019 14:22:44 +0000 (22:22 +0800)
packages/runtime-core/src/component.ts
packages/runtime-core/src/createRenderer.ts
packages/runtime-core/src/index.ts
packages/runtime-core/src/typeFlags.ts [moved from packages/runtime-core/src/shapeFlags.ts with 100% similarity]
packages/runtime-core/src/vnode.ts

index 4a36227c43eaf59c3630019fcba4e57f47db0eaf..b9bd41eb173d0e595b862dcabafb8692bb6866b5 100644 (file)
@@ -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 }
 
index 7923465aefe96d530843613aab13428649ea0a1b..e01a84278c9e2620cb382a95c641f2e54368eade 100644 (file)
@@ -34,7 +34,7 @@ import {
   FUNCTIONAL_COMPONENT,
   TEXT_CHILDREN,
   ARRAY_CHILDREN
-} from './shapeFlags'
+} from './typeFlags'
 
 const prodEffectOptions = {
   scheduler: queueJob
index cc12c13edf89a0ce22e7f83cf92a4dd1f6173f4c..ce76e3fe89471d71f66602a8b31982eedb61f562 100644 (file)
@@ -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'
index 56951a259bdb205142e0026a4c47fe44d85f13f2..f5b6033442db681dfb226208f78167d45a35473c 100644 (file)
@@ -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
+    : isObject(type)
+      ? STATEFUL_COMPONENT
+      : 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(