Skip to content

Commit a0c3425

Browse files
committed
avoid duplicate async resolution calls
1 parent 214fe5e commit a0c3425

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/instance/misc.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,33 @@ exports._applyFilter = function (id, args) {
3030

3131
exports._resolveComponent = function (id, cb) {
3232
var registry = this.$options.components
33-
var raw = registry[id]
34-
_.assertAsset(raw, 'component', id)
33+
var factory = registry[id]
34+
_.assertAsset(factory, 'component', id)
3535
// async component factory
36-
if (!raw.options) {
37-
if (raw.resolved) {
36+
if (!factory.options) {
37+
if (factory.resolved) {
3838
// cached
39-
cb(raw.resolved)
39+
cb(factory.resolved)
40+
} else if (factory.pending) {
41+
factory.pendingCallbacks.push(cb)
4042
} else {
41-
raw(function resolve (res) {
43+
factory.pending = true
44+
var cbs = factory.pendingCallbacks = [cb]
45+
factory(function resolve (res) {
4246
if (_.isPlainObject(res)) {
4347
res = _.Vue.extend(res)
4448
}
4549
// cache resolved
46-
raw.resolved = res
47-
cb(res)
50+
factory.resolved = res
51+
factory.pending = false
52+
// invoke callbacks
53+
for (var i = 0, l = cbs.length; i < l; i++) {
54+
cbs[i](res)
55+
}
4856
})
4957
}
5058
} else {
5159
// normal component
52-
cb(raw)
60+
cb(factory)
5361
}
5462
}

0 commit comments

Comments
 (0)