Browse Source

refactor(runtime-core): move updateCompnent into separate function

Evan You 6 years ago
parent
commit
cda50ea788
1 changed files with 40 additions and 32 deletions
  1. 40 32
      packages/runtime-core/src/renderer.ts

+ 40 - 32
packages/runtime-core/src/renderer.ts

@@ -968,38 +968,7 @@ function baseCreateRenderer(
         )
       }
     } else {
-      const instance = (n2.component = n1.component)!
-
-      if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
-        if (
-          __FEATURE_SUSPENSE__ &&
-          instance.asyncDep &&
-          !instance.asyncResolved
-        ) {
-          // async & still pending - just update props and slots
-          // since the component's reactive effect for render isn't set-up yet
-          if (__DEV__) {
-            pushWarningContext(n2)
-          }
-          updateComponentPreRender(instance, n2, optimized)
-          if (__DEV__) {
-            popWarningContext()
-          }
-          return
-        } else {
-          // normal update
-          instance.next = n2
-          // in case the child component is also queued, remove it to avoid
-          // double updating the same child component in the same flush.
-          invalidateJob(instance.update)
-          // instance.update is the reactive effect runner.
-          instance.update()
-        }
-      } else {
-        // no update needed. just copy over properties
-        n2.component = n1.component
-        n2.el = n1.el
-      }
+      updateComponent(n1, n2, parentComponent, optimized)
     }
   }
 
@@ -1077,6 +1046,45 @@ function baseCreateRenderer(
     }
   }
 
+  const updateComponent = (
+    n1: VNode,
+    n2: VNode,
+    parentComponent: ComponentInternalInstance | null,
+    optimized: boolean
+  ) => {
+    const instance = (n2.component = n1.component)!
+    if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
+      if (
+        __FEATURE_SUSPENSE__ &&
+        instance.asyncDep &&
+        !instance.asyncResolved
+      ) {
+        // async & still pending - just update props and slots
+        // since the component's reactive effect for render isn't set-up yet
+        if (__DEV__) {
+          pushWarningContext(n2)
+        }
+        updateComponentPreRender(instance, n2, optimized)
+        if (__DEV__) {
+          popWarningContext()
+        }
+        return
+      } else {
+        // normal update
+        instance.next = n2
+        // in case the child component is also queued, remove it to avoid
+        // double updating the same child component in the same flush.
+        invalidateJob(instance.update)
+        // instance.update is the reactive effect runner.
+        instance.update()
+      }
+    } else {
+      // no update needed. just copy over properties
+      n2.component = n1.component
+      n2.el = n1.el
+    }
+  }
+
   const setupRenderEffect: SetupRenderEffectFn = (
     instance,
     initialVNode,