@@ -25,7 +25,7 @@ import {
25
25
asVmProperty ,
26
26
} from './utils/instance'
27
27
import { getVueConstructor } from './runtimeContext'
28
- import { createObserver } from './reactivity/reactive'
28
+ import { createObserver , reactive } from './reactivity/reactive'
29
29
30
30
export function mixin ( Vue : VueConstructor ) {
31
31
Vue . mixin ( {
@@ -190,38 +190,59 @@ export function mixin(Vue: VueConstructor) {
190
190
function createSetupContext (
191
191
vm : ComponentInstance & { [ x : string ] : any }
192
192
) : SetupContext {
193
- const ctx = {
194
- slots : { } ,
195
- } as SetupContext
196
- const props : Array < string | [ string , string ] > = [
193
+ const ctx = { slots : { } } as SetupContext
194
+
195
+ const propsPlain = [
197
196
'root' ,
198
197
'parent' ,
199
198
'refs' ,
200
- 'attrs' ,
201
199
'listeners' ,
202
200
'isServer' ,
203
201
'ssrContext' ,
204
202
]
203
+ const propsReactiveProxy = [ 'attrs' ]
205
204
const methodReturnVoid = [ 'emit' ]
206
- props . forEach ( ( key ) => {
207
- let targetKey : string
208
- let srcKey : string
209
- if ( Array . isArray ( key ) ) {
210
- ; [ targetKey , srcKey ] = key
211
- } else {
212
- targetKey = srcKey = key
213
- }
214
- srcKey = `$${ srcKey } `
215
- proxy ( ctx , targetKey , {
205
+
206
+ propsPlain . forEach ( ( key ) => {
207
+ let srcKey = `$${ key } `
208
+ proxy ( ctx , key , {
216
209
get : ( ) => vm [ srcKey ] ,
217
210
set ( ) {
218
211
warn (
219
- `Cannot assign to '${ targetKey } ' because it is a read-only property` ,
212
+ `Cannot assign to '${ key } ' because it is a read-only property` ,
213
+ vm
214
+ )
215
+ } ,
216
+ } )
217
+ } )
218
+
219
+ propsReactiveProxy . forEach ( ( key ) => {
220
+ let srcKey = `$${ key } `
221
+ proxy ( ctx , key , {
222
+ get : ( ) => {
223
+ const data = reactive ( { } )
224
+ const source = vm [ srcKey ]
225
+
226
+ for ( const attr of Object . keys ( source ) ) {
227
+ proxy ( data , attr , {
228
+ get : ( ) => {
229
+ // to ensure it always return the latest value
230
+ return vm [ srcKey ] [ attr ]
231
+ } ,
232
+ } )
233
+ }
234
+
235
+ return data
236
+ } ,
237
+ set ( ) {
238
+ warn (
239
+ `Cannot assign to '${ key } ' because it is a read-only property` ,
220
240
vm
221
241
)
222
242
} ,
223
243
} )
224
244
} )
245
+
225
246
methodReturnVoid . forEach ( ( key ) => {
226
247
const srcKey = `$${ key } `
227
248
proxy ( ctx , key , {
0 commit comments