Просмотр исходного кода

tweak async component resolving

Evan You 9 лет назад
Родитель
Сommit
d2ff956b94
2 измененных файлов с 11 добавлено и 14 удалено
  1. 5 13
      src/core/vdom/create-component.js
  2. 6 1
      src/core/vdom/helpers/resolve-async-component.js

+ 5 - 13
src/core/vdom/create-component.js

@@ -114,19 +114,11 @@ export function createComponent (
 
   // async component
   if (isUndef(Ctor.cid)) {
-    if (isDef(Ctor.resolved)) {
-      Ctor = Ctor.resolved
-    } else {
-      Ctor = resolveAsyncComponent(Ctor, baseCtor, () => {
-        // it's ok to queue this on every render because
-        // $forceUpdate is buffered by the scheduler.
-        context.$forceUpdate()
-      })
-      if (!Ctor) {
-        // return nothing if this is indeed an async component
-        // wait for the callback to trigger parent update.
-        return
-      }
+    Ctor = resolveAsyncComponent(Ctor, baseCtor, context)
+    if (Ctor === undefined) {
+      // return nothing if this is indeed an async component
+      // wait for the callback to trigger parent update.
+      return
     }
   }
 

+ 6 - 1
src/core/vdom/helpers/resolve-async-component.js

@@ -8,8 +8,13 @@ import {
 export function resolveAsyncComponent (
   factory: Function,
   baseCtor: Class<Component>,
-  cb: Function
+  context: Component
 ): Class<Component> | void {
+  if (factory.resolved) {
+    return factory.resolved
+  }
+
+  const cb = () => context.$forceUpdate()
   if (factory.requested) {
     // pool callbacks
     factory.pendingCallbacks.push(cb)