8000 cache resolved async component on factory · Snoopbobb/vue@214fe5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 214fe5e

Browse files
committed
cache resolved async component on factory
1 parent 64643b6 commit 214fe5e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/instance/misc.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ exports._applyFilter = function (id, args) {
2121
* Resolve a component, depending on whether the component
2222
* is defined normally or using an async factory function.
2323
* Resolves synchronously if already resolved, otherwise
24-
* resolves asynchronously and replaces the factory with
25-
* the resolved component.
24+
* resolves asynchronously and caches the resolved
25+
* constructor on the factory.
2626
*
2727
* @param {String} id
2828
* @param {Function} cb
@@ -34,14 +34,21 @@ exports._resolveComponent = function (id, cb) {
3434
_.assertAsset(raw, 'component', id)
3535
// async component factory
3636
if (!raw.options) {
37-
raw(function resolve (res) {
38-
if (_.isPlainObject(res)) {
39-
res = _.Vue.extend(res)
40-
}
41-
registry[id] = res
42-
cb(res)
43-
})
37+
if (raw.resolved) {
38+
// cached
39+
cb(raw.resolved)
40+
} else {
41+
raw(function resolve (res) {
42+
if (_.isPlainObject(res)) {
43+
res = _.Vue.extend(res)
44+
}
45+
// cache resolved
46+
raw.resolved = res
47+
cb(res)
48+
})
49+
}
4450
} else {
51+
// normal component
4552
cb(raw)
4653
}
4754
}

0 commit comments

Comments
 (0)
0