Skip to content

Commit c670809

Browse files
committed
Vue.extend: move constructor caching from options to Vue.extend
1 parent deb43a8 commit c670809

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
@@ -44,6 +44,10 @@ var cid = 1
4444
exports.extend = function (extendOptions) {
4545
extendOptions = extendOptions || {}
4646
var Super = this
47+
var isFirstExtend = Super.cid === 0
48+
if (isFirstExtend && extendOptions._Ctor) {
49+
return extendOptions._Ctor
50+
}
4751
var name = extendOptions.name || Super.options.name
4852
var Sub = createClass(name || 'VueComponent')
4953
Sub.prototype = Object.create(Super.prototype)
@@ -65,6 +69,10 @@ exports.extend = function (extendOptions) {
6569
if (name) {
6670
Sub.options.components[name] = Sub
6771
}
72+
// cache constructor
73+
if (isFirstExtend) {
74+
extendOptions._Ctor = Sub
75+
}
6876
return Sub
6977
}
7078

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)