import { setClass, setDynamicProp } from './dom/prop'
import {
type RawSlots,
+ type Slot,
type StaticSlots,
dynamicSlotsProxyHandlers,
getSlot,
inheritAttrs?: boolean
props?: ComponentPropsOptions
emits?: EmitsOptions
- render?(ctx: any): Block
+ render?(
+ ctx: any,
+ props?: any,
+ emit?: EmitFn,
+ attrs?: any,
+ slots?: Record<string, Slot>,
+ ): Block
name?: string
vapor?: boolean
}
const setupFn = isFunction(component) ? component : component.setup
- const setupContext =
- setupFn && setupFn.length > 1 ? new SetupContext(instance) : null
const setupResult = setupFn
? setupFn(
instance.props,
// @ts-expect-error
- setupContext,
+ setupFn.length > 1 ? new SetupContext(instance) : null,
) || EMPTY_OBJ
: EMPTY_OBJ
instance.block = []
} else {
instance.setupState = setupResult
- instance.block = component.render.call(null, proxyRefs(setupResult))
+ instance.block = component.render.call(
+ null,
+ proxyRefs(setupResult),
+ instance.props,
+ instance.emit,
+ instance.attrs,
+ instance.slots,
+ )
}
} else {
// in prod result can only be block
rawProps: RawProps
rawSlots: RawSlots
+ emit: EmitFn
emitted: Record<string, boolean> | null
propsDefaults: Record<string, any> | null
this.block = null! // to be set
this.scope = new EffectScope(true)
+ this.emit = emit.bind(null, this)
this.provides = currentInstance
? currentInstance.provides
: Object.create(this.appContext.provides)
this.propsOptions = normalizePropsOptions(comp)
this.emitsOptions = normalizeEmitsOptions(comp)
}
-
- // TODO init slots
}
}
return value instanceof VaporComponentInstance
}
-export class SetupContext<E = EmitsOptions> {
+export class SetupContext {
attrs: Record<string, any>
- emit: EmitFn<E>
- // TODO slots: Readonly<StaticSlots>
+ emit: EmitFn
+ slots: Readonly<StaticSlots>
expose: (exposed?: Record<string, any>) => void
constructor(instance: VaporComponentInstance) {
this.attrs = instance.attrs
- this.emit = emit.bind(null, instance) as EmitFn<E>
- // this.slots = instance.slots
+ this.emit = instance.emit
+ this.slots = instance.slots
this.expose = (exposed = {}) => {
instance.exposed = exposed
}