refactor(runtime-core): remove attrsProxy and slotsProxy from instance (#11390)

This commit is contained in:
edison 2024-07-19 17:02:14 +08:00 committed by GitHub
parent 5df67e3675
commit 1b81d14bfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 16 deletions

View File

@ -396,9 +396,6 @@ export interface ComponentInternalInstance {
refs: Data
emit: EmitFn
attrsProxy: Data | null
slotsProxy: Slots | null
/**
* used for keeping track of .once event handlers on components
* @internal
@ -599,9 +596,6 @@ export function createComponentInstance(
setupState: EMPTY_OBJ,
setupContext: null,
attrsProxy: null,
slotsProxy: null,
// suspense related
suspense,
suspenseId: suspense ? suspense.pendingId : 0,
@ -1042,15 +1036,12 @@ const attrsProxyHandlers = __DEV__
* Dev-only
*/
function getSlotsProxy(instance: ComponentInternalInstance): Slots {
return (
instance.slotsProxy ||
(instance.slotsProxy = new Proxy(instance.slots, {
return new Proxy(instance.slots, {
get(target, key: string) {
track(instance, TrackOpTypes.GET, '$slots')
return target[key]
},
}))
)
})
}
export function createSetupContext(
@ -1084,6 +1075,7 @@ export function createSetupContext(
// We use getters in dev in case libs like test-utils overwrite instance
// properties (overwrites should not be done in prod)
let attrsProxy: Data
let slotsProxy: Slots
return Object.freeze({
get attrs() {
return (
@ -1092,7 +1084,7 @@ export function createSetupContext(
)
},
get slots() {
return getSlotsProxy(instance)
return slotsProxy || (slotsProxy = getSlotsProxy(instance))
},
get emit() {
return (event: string, ...args: any[]) => instance.emit(event, ...args)