]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: use util methods
authorEvan You <yyx990803@gmail.com>
Tue, 28 May 2019 02:28:25 +0000 (10:28 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 28 May 2019 02:28:25 +0000 (10:28 +0800)
packages/runtime-core/src/component.ts [new file with mode: 0644]
packages/runtime-core/src/createRenderer.ts
packages/runtime-core/src/index.ts
packages/runtime-core/src/vnode.ts [moved from packages/runtime-core/src/h.ts with 95% similarity]
tsconfig.json

diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts
new file mode 100644 (file)
index 0000000..9f67230
--- /dev/null
@@ -0,0 +1 @@
+export class Component {}
index daced6e7882674600229d7da30ab50a4fab0a091..2ce239e3d5c7c1888255de7934650c316d126fb1 100644 (file)
@@ -16,8 +16,9 @@ import {
   createVNode,
   VNode,
   VNodeChildren
-} from './h.js'
+} from './vnode.js'
 import { TEXT, CLASS, STYLE, PROPS, KEYED, UNKEYED } from './patchFlags'
+import { isString, isFunction, isArray } from '@vue/shared'
 
 const emptyArr: any[] = []
 const emptyObj: { [key: string]: any } = {}
@@ -82,8 +83,8 @@ export function createRenderer(options: RendererOptions) {
       processEmptyNode(n1, n2, container, anchor)
     } else if (type === Fragment) {
       processFragment(n1, n2, container, anchor, optimized)
-    } else if (typeof type === 'function') {
-      // TODO Component
+    } else if (isFunction(type)) {
+      processComponent(n1, n2, container, anchor)
     } else {
       processElement(n1, n2, container, anchor, optimized)
     }
@@ -144,7 +145,7 @@ export function createRenderer(options: RendererOptions) {
         hostPatchProp(el, key, vnode.props[key], null, false)
       }
     }
-    if (typeof vnode.children === 'string') {
+    if (isString(vnode.children)) {
       hostSetElementText(el, vnode.children)
     } else if (vnode.children != null) {
       mountChildren(vnode.children, el)
@@ -168,7 +169,7 @@ export function createRenderer(options: RendererOptions) {
     if (child == null) {
       // empty placeholder
       return createVNode(Empty)
-    } else if (Array.isArray(child)) {
+    } else if (isArray(child)) {
       // fragment
       return createVNode(Fragment, null, child)
     } else if (typeof child === 'object') {
@@ -322,6 +323,13 @@ export function createRenderer(options: RendererOptions) {
     }
   }
 
+  function processComponent(
+    n1: VNode | null,
+    n2: VNode,
+    container: HostNode,
+    anchor?: HostNode
+  ) {}
+
   function patchChildren(
     n1: VNode | null,
     n2: VNode,
@@ -359,20 +367,20 @@ export function createRenderer(options: RendererOptions) {
       }
     }
 
-    if (typeof c2 === 'string') {
+    if (isString(c2)) {
       // text children fast path
-      if (Array.isArray(c1)) {
+      if (isArray(c1)) {
         unmountChildren(c1 as VNode[])
       }
       hostSetElementText(container, c2)
     } else {
-      if (typeof c1 === 'string') {
+      if (isString(c1)) {
         hostSetElementText(container, '')
         if (c2 != null) {
           mountChildren(c2, container, anchor)
         }
-      } else if (Array.isArray(c1)) {
-        if (Array.isArray(c2)) {
+      } else if (isArray(c1)) {
+        if (isArray(c2)) {
           // two arrays, cannot assume anything, do full diff
           patchKeyedChildren(c1 as VNode[], c2, container, anchor, optimized)
         } else {
@@ -596,7 +604,7 @@ export function createRenderer(options: RendererOptions) {
     const shouldRemoveChildren = vnode.type === Fragment && doRemove
     if (vnode.dynamicChildren != null) {
       unmountChildren(vnode.dynamicChildren, shouldRemoveChildren)
-    } else if (Array.isArray(vnode.children)) {
+    } else if (isArray(vnode.children)) {
       unmountChildren(vnode.children as VNode[], shouldRemoveChildren)
     }
     if (doRemove) {
index 67477283887d59730a0c167a459d0d9ec5ba3af8..09bbadef42873ebaadc7147ccf3436ae49bee495 100644 (file)
@@ -6,7 +6,7 @@ export {
   Fragment,
   Text,
   Empty
-} from './h'
+} from './vnode'
 export { createRenderer, RendererOptions } from './createRenderer'
 export * from '@vue/observer'
 export { TEXT, CLASS, STYLE, PROPS, KEYED, UNKEYED } from './patchFlags'
similarity index 95%
rename from packages/runtime-core/src/h.ts
rename to packages/runtime-core/src/vnode.ts
index ef84138e064ff510d9d55666518959fefb8dc8b9..4bac668a9f58f367bdc0ad7904ab01eba01f698f 100644 (file)
@@ -1,3 +1,5 @@
+import { isFunction } from '@vue/shared'
+
 export const Fragment = Symbol('Fragment')
 export const Text = Symbol('Text')
 export const Empty = Symbol('Empty')
@@ -72,7 +74,7 @@ export function createVNode(
     dynamicProps,
     dynamicChildren: null
   }
-  if (patchFlag != null && shouldTrack) {
+  if (shouldTrack && (patchFlag != null || isFunction(type))) {
     trackDynamicNode(vnode)
   }
   return vnode
index ccb988349d5663f17eb6c3b1a3fc2db626d77f73..69423b402c405e2f007a045364d27555be4bbbfb 100644 (file)
@@ -26,8 +26,7 @@
       "@vue/observer": ["packages/observer/src"],
       "@vue/scheduler": ["packages/scheduler/src"],
       "@vue/compiler-core": ["packages/compiler-core/src"],
-      "@vue/server-renderer": ["packages/server-renderer/src"],
-      "@vue/decorators": ["packages/decorators/src"]
+      "@vue/server-renderer": ["packages/server-renderer/src"]
     }
   },
   "include": [