@@ -15,7 +15,8 @@ import {
15
15
shallowReadonly ,
16
16
ReactiveFlags ,
17
17
track ,
18
- TrackOpTypes
18
+ TrackOpTypes ,
19
+ unref
19
20
} from '@vue/reactivity'
20
21
import {
21
22
ExtractComputedReturns ,
@@ -198,8 +199,8 @@ export interface ComponentRenderContext {
198
199
_ : ComponentInternalInstance
199
200
}
200
201
201
- export const PublicInstanceProxyHandlers : ProxyHandler < any > = {
202
- get ( { _ : instance } : ComponentRenderContext , key : string ) {
202
+ export class PublicInstanceHandlers {
203
+ static get ( { _ : instance } : ComponentRenderContext , key : string ) {
203
204
const {
204
205
ctx,
205
206
setupState,
@@ -227,7 +228,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
227
228
if ( n !== undefined ) {
228
229
switch ( n ) {
229
230
case AccessTypes . SETUP :
230
- return setupState [ key ]
231
+ return unref ( setupState [ key ] )
231
232
case AccessTypes . DATA :
232
233
return data [ key ]
233
234
case AccessTypes . CONTEXT :
@@ -238,7 +239,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
238
239
}
239
240
} else if ( setupState !== EMPTY_OBJ && hasOwn ( setupState , key ) ) {
240
241
accessCache ! [ key ] = AccessTypes . SETUP
241
- return setupState [ key ]
242
+ return unref ( setupState [ key ] )
242
243
} else if ( data !== EMPTY_OBJ && hasOwn ( data , key ) ) {
243
244
accessCache ! [ key ] = AccessTypes . DATA
244
245
return data [ key ]
@@ -304,9 +305,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
304
305
)
305
306
}
306
307
}
307
- } ,
308
+ }
308
309
309
- set (
310
+ static set (
310
311
{ _ : instance } : ComponentRenderContext ,
311
312
key : string ,
312
313
value : any
@@ -344,9 +345,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
344
345
}
345
346
}
346
347
return true
347
- } ,
348
+ }
348
349
349
- has (
350
+ static has (
350
351
{
351
352
_ : { data, setupState, accessCache, ctx, type, appContext }
352
353
} : ComponentRenderContext ,
@@ -366,40 +367,35 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
366
367
}
367
368
}
368
369
369
- if ( __DEV__ && ! __TEST__ ) {
370
- PublicInstanceProxyHandlers . ownKeys = ( target : ComponentRenderContext ) => {
371
- warn (
372
- `Avoid app logic that relies on enumerating keys on a component instance. ` +
373
- `The keys will be empty in production mode to avoid performance overhead.`
374
- )
375
- return Reflect . ownKeys ( target )
370
+ export class RuntimeCompiledPublicInstanceHandlers {
371
+ static set (
372
+ instance : ComponentRenderContext ,
373
+ key : string ,
374
+ value : any
375
+ ) : boolean {
376
+ return PublicInstanceHandlers . set ( instance , key , value )
376
377
}
377
- }
378
378
379
- export const RuntimeCompiledPublicInstanceProxyHandlers = extend (
380
- { } ,
381
- PublicInstanceProxyHandlers ,
382
- {
383
- get ( target : ComponentRenderContext , key : string ) {
384
- // fast path for unscopables when using `with` block
385
- if ( ( key as any ) === Symbol . unscopables ) {
386
- return
387
- }
388
- return PublicInstanceProxyHandlers . get ! ( target , key , target )
389
- } ,
390
- has ( _ : ComponentRenderContext , key : string ) {
391
- const has = key [ 0 ] !== '_' && ! isGloballyWhitelisted ( key )
392
- if ( __DEV__ && ! has && PublicInstanceProxyHandlers . has ! ( _ , key ) ) {
393
- warn (
394
- `Property ${ JSON . stringify (
395
- key
396
- ) } should not start with _ which is a reserved prefix for Vue internals.`
397
- )
398
- }
399
- return has
379
+ static get ( target : ComponentRenderContext , key : string ) {
380
+ // fast path for unscopables when using `with` block
381
+ if ( ( key as any ) === Symbol . unscopables ) {
382
+ return
400
383
}
384
+ return PublicInstanceHandlers . get ( target , key )
401
385
}
402
- )
386
+
387
+ static has ( _ : ComponentRenderContext , key : string ) {
388
+ const has = key [ 0 ] !== '_' && ! isGloballyWhitelisted ( key )
389
+ if ( __DEV__ && ! has && PublicInstanceHandlers . has ( _ , key ) ) {
390
+ warn (
391
+ `Property ${ JSON . stringify (
392
+ key
393
+ ) } should not start with _ which is a reserved prefix for Vue internals.`
394
+ )
395
+ }
396
+ return has
397
+ }
398
+ }
403
399
404
400
// In dev mode, the proxy target exposes the same properties as seen on `this`
405
401
// for easier console inspection. In prod mode it will be an empty object so
0 commit comments