Skip to content

Commit a4b0438

Browse files
committed
handle async component for raw constructor :is
1 parent 82767a0 commit a4b0438

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/directives/internal/component.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ export default {
114114
/**
115115
* Resolve the component constructor to use when creating
116116
* the child vm.
117+
*
118+
* @param {String|Function} value
119+
* @param {Function} cb
117120
*/
118121

119-
resolveComponent (id, cb) {
122+
resolveComponent (value, cb) {
120123
var self = this
121-
var done = function (Component) {
122-
self.ComponentName = Component.options.name || id
124+
this.pendingComponentCb = cancellable(function (Component) {
125+
self.ComponentName =
126+
Component.options.name ||
127+
(typeof value === 'string' ? value : null)
123128
self.Component = Component
124129
cb()
125-
}
126-
if (typeof id === 'function') {
127-
done(id)
128-
} else {
129-
this.pendingComponentCb = cancellable(done)
130-
this.vm._resolveComponent(id, this.pendingComponentCb)
131-
}
130+
})
131+
this.vm._resolveComponent(value, this.pendingComponentCb)
132132
},
133133

134134
/**

src/instance/internal/misc.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ export default function (Vue) {
5252
* resolves asynchronously and caches the resolved
5353
* constructor on the factory.
5454
*
55-
* @param {String} id
55+
* @param {String|Function} value
5656
* @param {Function} cb
5757
*/
5858

59-
Vue.prototype._resolveComponent = function (id, cb) {
60-
var factory = resolveAsset(this.$options, 'components', id)
61-
if (process.env.NODE_ENV !== 'production') {
62-
assertAsset(factory, 'component', id)
59+
Vue.prototype._resolveComponent = function (value, cb) {
60+
var factory
61+
if (typeof value === 'function') {
62+
factory = value
63+
} else {
64+
factory = resolveAsset(this.$options, 'components', value)
65+
if (process.env.NODE_ENV !== 'production') {
66+
assertAsset(factory, 'component', value)
67+
}
6368
}
6469
if (!factory) {
6570
return
@@ -87,7 +92,8 @@ export default function (Vue) {
8792
}
8893
}, function reject (reason) {
8994
process.env.NODE_ENV !== 'production' && warn(
90-
'Failed to resolve async component: ' + id + '. ' +
95+
'Failed to resolve async component' +
96+
(typeof value === 'string' ? ': ' + value : '') + '. ' +
9197
(reason ? '\nReason: ' + reason : '')
9298
)
9399
})

test/unit/specs/directives/internal/component_spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,21 @@ describe('Component', function () {
137137
it(':is using raw component constructor', function () {
138138
new Vue({
139139
el: el,
140-
template: '<component :is="$options.components.test">',
140+
template:
141+
'<component :is="$options.components.test"></component>' +
142+
'<component :is="$options.components.async"></component>',
141143
components: {
142144
test: {
143145
template: 'hi'
146+
},
147+
async: function (resolve) {
148+
resolve({
149+
template: 'ho'
150+
})
144151
}
145152
}
146153
})
147-
expect(el.textContent).toBe('hi')
154+
expect(el.textContent).toBe('hiho')
148155
})
149156

150157
it('keep-alive', function (done) {

0 commit comments

Comments
 (0)