feat(runtime-core): add generic option for getCurrentInstance

This commit is contained in:
zhiyuanzmj 2025-05-29 11:40:09 +08:00
parent 1ef6e6edb7
commit 7d84f7d85f
1 changed files with 18 additions and 3 deletions

View File

@ -16,10 +16,25 @@ export let currentInstance: GenericComponentInstance | null = null
export const getCurrentGenericInstance: () => GenericComponentInstance | null =
() => currentInstance || currentRenderingInstance
export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
currentInstance && !currentInstance.vapor
? (currentInstance as ComponentInternalInstance)
/**
* Retrieves the current component instance.
*
* @param generic - A boolean flag indicating whether to return a generic component instance.
* If `true`, returns a `GenericComponentInstance` including vapor instance.
* If `false` or unset, returns a `ComponentInternalInstance` if available.
* @returns The current component instance, or `null` if no instance is active.
*/
export function getCurrentInstance(
generic: true,
): GenericComponentInstance | null
export function getCurrentInstance(
generic?: boolean,
): ComponentInternalInstance | null
export function getCurrentInstance(generic?: boolean) {
return currentInstance && (generic || !currentInstance.vapor)
? currentInstance
: currentRenderingInstance
}
export let isInSSRComponentSetup = false