@@ -21,6 +21,13 @@ import {
21
21
noop
22
22
} from '../util/index'
23
23
24
+ const sharedPropertyDefinition = {
25
+ enumerable : true ,
26
+ configurable : true ,
27
+ get : noop ,
28
+ set : noop
29
+ }
30
+
24
31
export function initState ( vm : Component ) {
25
32
vm . _watchers = [ ]
26
33
const opts = vm . $options
@@ -71,7 +78,9 @@ function initProps (vm: Component, propsOptions: Object) {
71
78
} else {
72
79
defineReactive ( props , key , value )
73
80
}
74
- proxy ( vm , props , key )
81
+ if ( ! ( key in vm ) ) {
82
+ proxy ( vm , `_props` , key )
83
+ }
75
84
}
76
85
observerState . shouldConvert = true
77
86
}
@@ -101,7 +110,7 @@ function initData (vm: Component) {
101
110
vm
102
111
)
103
112
} else if ( ! isReserved ( keys [ i ] ) ) {
104
- proxy ( vm , data , keys [ i ] )
113
+ proxy ( vm , `_data` , keys [ i ] )
105
114
}
106
115
}
107
116
// observe data
@@ -128,28 +137,21 @@ function initComputed (vm: Component, computed: Object) {
128
137
}
129
138
}
130
139
131
- const computedSharedDefinition = {
132
- enumerable : true ,
133
- configurable : true ,
134
- get : noop ,
135
- set : noop
136
- }
137
-
138
140
export function defineComputed ( target : any , key : string , userDef : Object | Function ) {
139
141
if ( typeof userDef === 'function' ) {
140
- computedSharedDefinition . get = createComputedGetter ( key )
141
- computedSharedDefinition . set = noop
142
+ sharedPropertyDefinition . get = createComputedGetter ( key )
143
+ sharedPropertyDefinition . set = noop
142
144
} else {
143
- computedSharedDefinition . get = userDef . get
145
+ sharedPropertyDefinition . get = userDef . get
144
146
? userDef . cache !== false
145
147
? createComputedGetter ( key )
146
148
: userDef . get
147
149
: noop
148
- computedSharedDefinition . set = userDef . set
150
+ sharedPropertyDefinition . set = userDef . set
149
151
? userDef . set
150
152
: noop
151
153
}
152
- Object . defineProperty ( target , key , computedSharedDefinition )
154
+ Object . defineProperty ( target , key , sharedPropertyDefinition )
153
155
}
154
156
155
157
function createComputedGetter ( key ) {
@@ -249,15 +251,12 @@ export function stateMixin (Vue: Class<Component>) {
249
251
}
250
252
}
251
253
252
- function proxy ( vm : Component , source : Object , key : string ) {
253
- Object . defineProperty ( vm , key , {
254
- configurable : true ,
255
- enumerable : true ,
256
- get : function proxyGetter ( ) {
257
- return source [ key ]
258
- } ,
259
- set : function proxySetter ( val ) {
260
- source [ key ] = val
261
- }
262
- } )
254
+ export function proxy ( target : Object , sourceKey : string , key : string ) {
255
+ sharedPropertyDefinition . get = function proxyGetter ( ) {
256
+ return this [ sourceKey ] [ key ]
257
+ }
258
+ sharedPropertyDefinition . set = function proxySetter ( val ) {
259
+ this [ sourceKey ] [ key ] = val
260
+ }
261
+ Object . defineProperty ( target , key , sharedPropertyDefinition )
263
262
}
0 commit comments