]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: use shared options for component effect runners
authorEvan You <yyx990803@gmail.com>
Wed, 29 May 2019 01:19:01 +0000 (09:19 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 29 May 2019 01:19:01 +0000 (09:19 +0800)
packages/runtime-core/src/createRenderer.ts

index 5067fd4dc64c7f74010f5f1d873b0b5fa393f0e2..b379c44639edd97be930a5f429bed58408cfd851 100644 (file)
@@ -18,6 +18,10 @@ import { TEXT, CLASS, STYLE, PROPS, KEYED, UNKEYED } from './patchFlags'
 import { queueJob, queuePostFlushCb, flushPostFlushCbs } from './scheduler'
 import { effect, stop } from '@vue/observer'
 
+const sharedEffectOptions = {
+  scheduler: queueJob
+}
+
 function isSameType(n1: VNode, n2: VNode): boolean {
   return n1.type === n2.type && n1.key === n2.key
 }
@@ -347,50 +351,45 @@ export function createRenderer(options: RendererOptions) {
     const instance: ComponentInstance = (vnode.component = createComponentInstance(
       vnode
     ))
-    instance.update = effect(
-      () => {
-        if (!instance.vnode) {
-          // initial mount
-          instance.vnode = vnode
-          const subTree = (instance.subTree = renderComponentRoot(instance))
-          if (instance.bm !== null) {
-            invokeHooks(instance.bm)
-          }
-          patch(null, subTree, container, anchor)
-          vnode.el = subTree.el
-          // mounted hook
-          if (instance.m !== null) {
-            queuePostFlushCb(instance.m)
-          }
-        } else {
-          // this is triggered by processComponent with `next` already set
-          const { next } = instance
-          if (next != null) {
-            next.component = instance
-            instance.vnode = next
-            instance.next = null
-          }
-          const prevTree = instance.subTree as VNode
-          const nextTree = (instance.subTree = renderComponentRoot(instance))
-          patch(
-            prevTree,
-            nextTree,
-            container || hostParentNode(prevTree.el),
-            anchor || getNextHostNode(prevTree)
-          )
-          if (next != null) {
-            next.el = nextTree.el
-          }
-          // upated hook
-          if (instance.u !== null) {
-            queuePostFlushCb(instance.u)
-          }
+    instance.update = effect(() => {
+      if (!instance.vnode) {
+        // initial mount
+        instance.vnode = vnode
+        const subTree = (instance.subTree = renderComponentRoot(instance))
+        if (instance.bm !== null) {
+          invokeHooks(instance.bm)
+        }
+        patch(null, subTree, container, anchor)
+        vnode.el = subTree.el
+        // mounted hook
+        if (instance.m !== null) {
+          queuePostFlushCb(instance.m)
+        }
+      } else {
+        // this is triggered by processComponent with `next` already set
+        const { next } = instance
+        if (next != null) {
+          next.component = instance
+          instance.vnode = next
+          instance.next = null
+        }
+        const prevTree = instance.subTree as VNode
+        const nextTree = (instance.subTree = renderComponentRoot(instance))
+        patch(
+          prevTree,
+          nextTree,
+          container || hostParentNode(prevTree.el),
+          anchor || getNextHostNode(prevTree)
+        )
+        if (next != null) {
+          next.el = nextTree.el
+        }
+        // upated hook
+        if (instance.u !== null) {
+          queuePostFlushCb(instance.u)
         }
-      },
-      {
-        scheduler: queueJob
       }
-    )
+    }, sharedEffectOptions)
   }
 
   function patchChildren(