@@ -14,7 +14,8 @@ import {
14
14
createRenderContext ,
15
15
exposePropsOnRenderContext ,
16
16
exposeSetupStateOnRenderContext ,
17
- ComponentPublicInstanceConstructor
17
+ ComponentPublicInstanceConstructor ,
18
+ publicPropertiesMap
18
19
} from './componentPublicInstance'
19
20
import {
20
21
ComponentPropsOptions ,
@@ -169,7 +170,7 @@ export interface SetupContext<E = EmitsOptions> {
169
170
attrs : Data
170
171
slots : Slots
171
172
emit : EmitFn < E >
172
- expose : ( exposed : Record < string , any > ) => void
173
+ expose : ( exposed ? : Record < string , any > ) => void
173
174
}
174
175
175
176
/**
@@ -291,6 +292,7 @@ export interface ComponentInternalInstance {
291
292
292
293
// exposed properties via expose()
293
294
exposed : Record < string , any > | null
295
+ exposeProxy : Record < string , any > | null
294
296
295
297
/**
296
298
* alternative proxy used only for runtime-compiled render functions using
@@ -447,6 +449,7 @@ export function createComponentInstance(
447
449
render : null ,
448
450
proxy : null ,
449
451
exposed : null ,
452
+ exposeProxy : null ,
450
453
withProxy : null ,
451
454
effects : null ,
452
455
provides : parent ? parent . provides : Object . create ( appContext . provides ) ,
@@ -837,7 +840,7 @@ export function createSetupContext(
837
840
if ( __DEV__ && instance . exposed ) {
838
841
warn ( `expose() should be called only once per setup().` )
839
842
}
840
- instance . exposed = proxyRefs ( exposed )
843
+ instance . exposed = exposed || { }
841
844
}
842
845
843
846
if ( __DEV__ ) {
@@ -868,6 +871,23 @@ export function createSetupContext(
868
871
}
869
872
}
870
873
874
+ export function getExposeProxy ( instance : ComponentInternalInstance ) {
875
+ if ( instance . exposed ) {
876
+ return (
877
+ instance . exposeProxy ||
878
+ ( instance . exposeProxy = new Proxy ( proxyRefs ( markRaw ( instance . exposed ) ) , {
879
+ get ( target , key : string ) {
880
+ if ( key in target ) {
881
+ return target [ key ]
882
+ } else if ( key in publicPropertiesMap ) {
883
+ return publicPropertiesMap [ key ] ( instance )
884
+ }
885
+ }
886
+ } ) )
887
+ )
888
+ }
889
+ }
890
+
871
891
// record effects created during a component's setup() so that they can be
872
892
// stopped when the component unmounts
873
893
export function recordInstanceBoundEffect (
0 commit comments