This commit is contained in:
Evan You 2015-05-11 00:21:31 -04:00
parent 3d9524577e
commit 40922468d7
4 changed files with 1610 additions and 1512 deletions

1671
dist/vue.js vendored

File diff suppressed because it is too large Load Diff

4
dist/vue.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -38,10 +38,11 @@ module.exports = {
}
// if static, build right now.
if (!this._isDynamicLiteral) {
this.resolveCtor(this.expression)
this.resolveCtor(this.expression, _.bind(function () {
var child = this.build()
child.$before(this.ref)
this.setCurrent(child)
}, this))
} else {
// check dynamic component params
this.readyEvent = this._checkParam('wait-for')
@ -60,10 +61,15 @@ module.exports = {
* the child vm.
*/
resolveCtor: function (id) {
this.ctorId = id
this.Ctor = this.vm.$options.components[id]
_.assertAsset(this.Ctor, 'component', id)
resolveCtor: function (id, cb) {
var self = this
// TODO handle update/teardown before the component
// is actually resolved
this.vm._resolveComponent(id, function (ctor) {
self.ctorId = id
self.Ctor = ctor
cb()
})
},
/**
@ -139,12 +145,12 @@ module.exports = {
update: function (value) {
if (!value) {
// just destroy and remove current
// just remove current
this.unbuild()
this.remove(this.childVM)
this.unsetCurrent()
} else {
this.resolveCtor(value)
this.resolveCtor(value, _.bind(function () {
this.unbuild()
var newComponent = this.build()
var self = this
@ -155,6 +161,7 @@ module.exports = {
} else {
this.swapTo(newComponent)
}
}, this))
}
},

View File

@ -16,3 +16,21 @@ exports._applyFilter = function (id, args) {
_.assertAsset(filter, 'filter', id)
return (filter.read || filter).apply(this, args)
}
exports._resolveComponent = function (id, cb) {
var registry = this.$options.components
var raw = registry[id]
_.assertAsset(raw, 'component', id)
// async component factory
if (!raw.options) {
raw(function resolve (res) {
if (_.isPlainObject(res)) {
res = _.Vue.extend(res)
}
registry[id] = res
cb(res)
})
} else {
cb(raw)
}
}