@@ -15,38 +15,48 @@ var internalHooks = [
15
15
'activate'
16
16
]
17
17
18
- function decorator ( options ) {
19
- return function ( Component ) {
20
- options . name = options . name || Component . name
21
- // prototype props.
22
- var proto = Component . prototype
23
- Object . getOwnPropertyNames ( proto ) . forEach ( function ( key ) {
24
- if ( key === 'constructor' ) {
25
- return
26
- }
27
- // hooks
28
- if ( internalHooks . indexOf ( key ) > - 1 ) {
29
- options [ key ] = proto [ key ]
30
- return
31
- }
32
- var descriptor = Object . getOwnPropertyDescriptor ( proto , key )
33
- if ( typeof descriptor . value === 'function' ) {
34
- // methods
35
- ( options . methods || ( options . methods = { } ) ) [ key ] = descriptor . value
36
- } else if ( descriptor . get || descriptor . set ) {
37
- // computed properties
38
- ( options . computed || ( options . computed = { } ) ) [ key ] = {
39
- get : descriptor . get ,
40
- set : descriptor . set
41
- }
18
+ function componentFactory ( Component , options ) {
19
+ if ( ! options ) {
20
+ options = { }
21
+ }
22
+ options . name = options . name || Component . name
23
+ // prototype props.
24
+ var proto = Component . prototype
25
+ Object . getOwnPropertyNames ( proto ) . forEach ( function ( key ) {
26
+ if ( key === 'constructor' ) {
27
+ return
28
+ }
29
+ // hooks
30
+ if ( internalHooks . indexOf ( key ) > - 1 ) {
31
+ options [ key ] = proto [ key ]
32
+ return
33
+ }
34
+ var descriptor = Object . getOwnPropertyDescriptor ( proto , key )
35
+ if ( typeof descriptor . value === 'function' ) {
36
+ // methods
37
+ ( options . methods || ( options . methods = { } ) ) [ key ] = descriptor . value
38
+ } else if ( descriptor . get || descriptor . set ) {
39
+ // computed properties
40
+ ( options . computed || ( options . computed = { } ) ) [ key ] = {
41
+ get : descriptor . get ,
42
+ set : descriptor . set
42
43
}
43
- } )
44
- // find super
45
- var Super = proto . __proto__ . constructor
46
- if ( ! ( Super instanceof Vue ) ) {
47
- Super = Vue
48
44
}
49
- return Super . extend ( options )
45
+ } )
46
+ // find super
47
+ var Super = proto . __proto__ . constructor
48
+ if ( ! ( Super instanceof Vue ) ) {
49
+ Super = Vue
50
+ }
51
+ return Super . extend ( options )
52
+ }
53
+
54
+ function decorator ( options ) {
55
+ if ( typeof options === 'function' ) {
56
+ return componentFactory ( options )
57
+ }
58
+ return function ( Component ) {
59
+ return componentFactory ( Component , options )
50
60
}
51
61
}
52
62
0 commit comments