wip: avoid proxy when slots are static

This commit is contained in:
Evan You 2024-12-06 23:10:41 +08:00
parent 91fc0d1251
commit 8331aa43c4
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
2 changed files with 7 additions and 3 deletions

View File

@ -35,7 +35,7 @@ import { setClass, setDynamicProp } from './dom/prop'
import {
type RawSlots,
type StaticSlots,
slotsProxyHandlers,
dynamicSlotsProxyHandlers,
} from './componentSlots'
export { currentInstance } from '@vue/runtime-dom'
@ -257,7 +257,11 @@ export class VaporComponentInstance implements GenericComponentInstance {
}
// init slots
this.slots = rawSlots ? new Proxy(rawSlots, slotsProxyHandlers) : EMPTY_OBJ
this.slots = rawSlots
? rawSlots.$
? new Proxy(rawSlots, dynamicSlotsProxyHandlers)
: rawSlots
: EMPTY_OBJ
if (__DEV__) {
// validate props

View File

@ -11,7 +11,7 @@ export type Slot = (...args: any[]) => Block
export type DynamicSlot = { name: string; fn: Slot }
export type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
export const slotsProxyHandlers: ProxyHandler<RawSlots> = {
export const dynamicSlotsProxyHandlers: ProxyHandler<RawSlots> = {
get: getSlot,
has: (target, key: string) => !!getSlot(target, key),
getOwnPropertyDescriptor(target, key: string) {