فهرست منبع

add reject fn to async component factory

Evan You 11 سال پیش
والد
کامیت
ba896479e2
2فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 6 0
      src/instance/misc.js
  2. 13 0
      test/unit/specs/async_component_spec.js

+ 6 - 0
src/instance/misc.js

@@ -57,6 +57,7 @@ exports._resolveComponent = function (id, cb) {
       // cached
       cb(factory.resolved)
     } else if (factory.requested) {
+      // pool callbacks
       factory.pendingCallbacks.push(cb)
     } else {
       factory.requested = true
@@ -71,6 +72,11 @@ exports._resolveComponent = function (id, cb) {
         for (var i = 0, l = cbs.length; i < l; i++) {
           cbs[i](res)
         }
+      }, function reject (reason) {
+        _.warn(
+          'Failed to resolve async component: ' + id + '. ' +
+          (reason ? '\nReason: ' + reason : '')
+        )
       })
     }
   } else {

+ 13 - 0
test/unit/specs/async_component_spec.js

@@ -182,6 +182,19 @@ describe('Async components', function () {
         done()
       }
     })
+
+    it('warn reject', function () {
+      var vm = new Vue({
+        el: el,
+        template: '<test></test>',
+        components: {
+          test: function (resolve, reject) {
+            reject('nooooo')
+          }
+        }
+      })
+      expect(hasWarned(_, 'Reason: nooooo')).toBe(true)
+    })
   })
 
   describe('v-repeat', function () {