1
1
/**
2
- * vue-class-component v6.1.2
3
- * (c) 2015-2017 Evan You
2
+ * vue-class-component v6.2.0
3
+ * (c) 2015-present Evan You
4
4
* @license MIT
5
5
*/
6
6
( function ( global , factory ) {
@@ -26,6 +26,13 @@ function createDecorator(factory) {
26
26
Ctor . __decorators__ . push ( function ( options ) { return factory ( options , key , index ) ; } ) ;
27
27
} ;
28
28
}
29
+ function mixins ( ) {
30
+ var Ctors = [ ] ;
31
+ for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
32
+ Ctors [ _i ] = arguments [ _i ] ;
33
+ }
34
+ return Vue . extend ( { mixins : Ctors } ) ;
35
+ }
29
36
function isPrimitive ( value ) {
30
37
var type = typeof value ;
31
38
return value == null || ( type !== "object" && type !== "function" ) ;
@@ -37,10 +44,13 @@ function warn(message) {
37
44
}
38
45
39
46
function collectDataFromConstructor ( vm , Component ) {
47
+ // override _init to prevent to init as Vue instance
40
48
var originalInit = Component . prototype . _init ;
41
49
Component . prototype . _init = function ( ) {
42
50
var _this = this ;
51
+ // proxy to actual vm
43
52
var keys = Object . getOwnPropertyNames ( vm ) ;
53
+ // 2.2.0 compat (props are no longer exposed as self properties)
44
54
if ( vm . $options . props ) {
45
55
for ( var key in vm . $options . props ) {
46
56
if ( ! vm . hasOwnProperty ( key ) ) {
@@ -58,8 +68,11 @@ function collectDataFromConstructor(vm, Component) {
58
68
}
59
69
} ) ;
60
70
} ;
71
+ // should be acquired class property values
61
72
var data = new Component ( ) ;
73
+ // restore original _init to avoid memory leak (#209)
62
74
Component . prototype . _init = originalInit ;
75
+ // create plain data object
63
76
var plainData = { } ;
64
77
Object . keys ( data ) . forEach ( function ( key ) {
65
78
if ( data [ key ] !== undefined ) {
@@ -88,25 +101,29 @@ var $internalHooks = [
88
101
'activated' ,
89
102
'deactivated' ,
90
103
'render' ,
91
- 'errorCaptured'
104
+ 'errorCaptured' // 2.5
92
105
] ;
93
106
function componentFactory ( Component , options ) {
94
107
if ( options === void 0 ) { options = { } ; }
95
108
options . name = options . name || Component . _componentTag || Component . name ;
109
+ // prototype props.
96
110
var proto = Component . prototype ;
97
111
Object . getOwnPropertyNames ( proto ) . forEach ( function ( key ) {
98
112
if ( key === 'constructor' ) {
99
113
return ;
100
114
}
115
+ // hooks
101
116
if ( $internalHooks . indexOf ( key ) > - 1 ) {
102
117
options [ key ] = proto [ key ] ;
103
118
return ;
104
119
}
105
120
var descriptor = Object . getOwnPropertyDescriptor ( proto , key ) ;
106
121
if ( typeof descriptor . value === 'function' ) {
122
+ // methods
107
123
( options . methods || ( options . methods = { } ) ) [ key ] = descriptor . value ;
108
124
}
109
125
else if ( descriptor . get || descriptor . set ) {
126
+ // computed properties
110
127
( options . computed || ( options . computed = { } ) ) [ key ] = {
111
128
get : descriptor . get ,
112
129
set : descriptor . set
@@ -118,11 +135,13 @@ function componentFactory(Component, options) {
118
135
return collectDataFromConstructor ( this , Component ) ;
119
136
}
120
137
} ) ;
138
+ // decorate options
121
139
var decorators = Component . __decorators__ ;
122
140
if ( decorators ) {
123
141
decorators . forEach ( function ( fn ) { return fn ( options ) ; } ) ;
124
142
delete Component . __decorators__ ;
125
143
}
144
+ // find super
126
145
var superProto = Object . getPrototypeOf ( Component . prototype ) ;
127
146
var Super = superProto instanceof Vue
128
147
? superProto . constructor
@@ -132,27 +151,44 @@ function componentFactory(Component, options) {
132
151
return Extended ;
133
152
}
134
153
var reservedPropertyNames = [
154
+ // Unique id
135
155
'cid' ,
156
+ // Super Vue constructor
136
157
'super' ,
158
+ // Component options that will be used by the component
137
159
'options' ,
138
160
'superOptions' ,
139
161
'extendOptions' ,
140
162
'sealedOptions' ,
163
+ // Private assets
141
164
'component' ,
142
165
'directive' ,
143
166
'filter'
144
167
] ;
145
168
function forwardStaticMembers ( Extended , Original , Super ) {
169
+ // We have to use getOwnPropertyNames since Babel registers methods as non-enumerable
146
170
Object . getOwnPropertyNames ( Original ) . forEach ( function ( key ) {
171
+ // `prototype` should not be overwritten
147
172
if ( key === 'prototype' ) {
148
173
return ;
149
174
}
175
+ // Some browsers does not allow reconfigure built-in properties
150
176
var extendedDescriptor = Object . getOwnPropertyDescriptor ( Extended , key ) ;
151
177
if ( extendedDescriptor && ! extendedDescriptor . configurable ) {
152
178
return ;
153
179
}
154
180
var descriptor = Object . getOwnPropertyDescriptor ( Original , key ) ;
181
+ // If the user agent does not support `__proto__` or its family (IE <= 10),
182
+ // the sub class properties may be inherited properties from the super class in TypeScript.
183
+ // We need to exclude such properties to prevent to overwrite
184
+ // the component options object which stored on the extended constructor (See #192).
185
+ // If the value is a referenced value (object or function),
186
+ // we can check equality of them and exclude it if they have the same reference.
187
+ // If it is a primitive value, it will be forwarded for safety.
155
188
if ( ! hasProto ) {
189
+ // Only `cid` is explicitly exluded from property forwarding
190
+ // because we cannot detect whether it is a inherited property or not
191
+ // on the no `__proto__` environment even though the property is reserved.
156
192
if ( key === 'cid' ) {
157
193
return ;
158
194
}
@@ -163,6 +199,7 @@ function forwardStaticMembers(Extended, Original, Super) {
163
199
return ;
164
200
}
165
201
}
202
+ // Warn if the users manually declare reserved properties
166
203
if ( "development" !== 'production'
167
204
&& reservedPropertyNames . indexOf ( key ) >= 0 ) {
168
205
warn ( "Static property name '" + key + "' declared on class '" + Original . name + "' " +
@@ -189,8 +226,9 @@ function Component(options) {
189
226
} ) ( Component || ( Component = { } ) ) ;
190
227
var Component$1 = Component ;
191
228
192
- exports [ ' default' ] = Component$1 ;
229
+ exports . default = Component$1 ;
193
230
exports . createDecorator = createDecorator ;
231
+ exports . mixins = mixins ;
194
232
195
233
Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
196
234
0 commit comments