File tree Expand file tree Collapse file tree 2 files changed +16
-20
lines changed Expand file tree Collapse file tree 2 files changed +16
-20
lines changed Original file line number Diff line number Diff line change @@ -65,12 +65,8 @@ export function componentFactory (
6565
6666 // find super
6767 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 )
7672}
Original file line number Diff line number Diff line change @@ -3,19 +3,19 @@ import { VueClass } from './declarations'
33import { noop } from './util'
44
55export 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+ }
1516
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 ( )
1919
2020 // create plain data object
2121 const plainData = { }
You can’t perform that action at this time.
0 commit comments