8000 Vue.extend: move constructor caching from options to Vue.extend · Aphasia-GitHub/vue@207c8f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 207c8f0

Browse files
committed
Vue.extend: move constructor caching from options to Vue.extend
1 parent eee5691 commit 207c8f0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/api/global.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ var cid = 1
3939
exports.extend = function (extendOptions) {
4040
extendOptions = extendOptions || {}
4141
var Super = this
42+
var isFirstExtend = Super.cid === 0
43+
if (isFirstExtend && extendOptions._Ctor) {
44+
return extendOptions._Ctor
45+
}
4246
var name = extendOptions.name || Super.options.name
4347
var Sub = createClass(name || 'VueComponent')
4448
Sub.prototype = Object.create(Super.prototype)
@@ -60,6 +64,10 @@ exports.extend = function (extendOptions) {
6064
if (name) {
6165
Sub.options.components[name] = Sub
6266
}
67+
// cache constructor
68+
if (isFirstExtend) {
69+
extendOptions._Ctor = Sub
70+
}
6371
return Sub
6472
}
6573

src/util/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function guardComponents (options) {
232232
def = components[key]
233233
if (_.isPlainObject(def)) {
234234
def.name = def.name || key
235-
components[key] = def._Ctor || (def._Ctor = _.Vue.extend(def))
235+
components[key] = _.Vue.extend(def)
236236
}
237237
}
238238
}

0 commit comments

Comments
 (0)
0