]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-core): move updateCompnent into separate function
authorEvan You <yyx990803@gmail.com>
Fri, 10 Apr 2020 13:55:38 +0000 (09:55 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 10 Apr 2020 14:19:26 +0000 (10:19 -0400)
packages/runtime-core/src/renderer.ts

index b6ac0258cdd928e643eab508f73eaf9bc0239937..ab854b11f00af7e014e5d182ef863494e8e6b36e 100644 (file)
@@ -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,