File tree 2 files changed +16
-20
lines changed 2 files changed +16
-20
lines changed Original file line number Diff line number Diff line change @@ -65,12 +65,8 @@ export function componentFactory (
65
65
66
66
// find super
67
67
const superProto = Object . getPrototypeOf ( Component . prototype )
68
- if ( ! ( superProto instanceof Vue ) ) {
69
- Component . prototype = Object . create ( Vue . prototype )
70
- Component . prototype . constructor = Component
71
- Object . keys ( Vue ) . forEach ( key => {
72
- Component [ key ] = Vue [ key ]
73
- } )
74
- }
75
- return Component . extend ( options )
68
+ const Super = superProto instanceof Vue
69
+ ? superProto . constructor as VueClass
70
+ : Vue
71
+ return Super . extend ( options )
76
72
}
Original file line number Diff line number Diff line change @@ -3,19 +3,19 @@ import { VueClass } from './declarations'
3
3
import { noop } from './util'
4
4
5
5
export function collectDataFromConstructor ( vm : Vue , Component : VueClass ) {
6
- // Create dummy Vue instance to collect
7
- // initial class properties from the component constructor.
8
- // To prevent to print warning,
9
- // the data object should inherit Vue.prototype.
10
- const data = Object . create ( vm , {
11
- _init : {
12
- get : ( ) => noop
13
- }
14
- } )
6
+ // override _init to prevent to init as Vue instance
7
+ Component . prototype . _init = function ( this : Vue ) {
8
+ // proxy to actual vm
9
+ Object . getOwnPropertyNames ( vm ) . forEach ( key => {
10
+ Object . defineProperty ( this , key , {
11
+ get : ( ) => vm [ key ] ,
12
+ set : value => vm [ key ] = value
13
+ } )
14
+ } )
15
+ }
15
16
16
- // call constructor with passing dummy instance
17
- // `data` object will have initial data
18
- Component . call ( data )
17
+ // should be acquired class property values
18
+ const data = new Component ( )
19
19
20
20
// create plain data object
21
21
const plainData = { }
You can’t perform that action at this time.
0 commit comments