Skip to content

Commit 7d84f7d

Browse files
committed
feat(runtime-core): add generic option for getCurrentInstance
1 parent 1ef6e6e commit 7d84f7d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/runtime-core/src/componentCurrentInstance.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,25 @@ export let currentInstance: GenericComponentInstance | null = null
1616
export const getCurrentGenericInstance: () => GenericComponentInstance | null =
1717
() => currentInstance || currentRenderingInstance
1818

19-
export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
20-
currentInstance && !currentInstance.vapor
21-
? (currentInstance as ComponentInternalInstance)
19+
/**
20+
* Retrieves the current component instance.
21+
*
22+
* @param generic - A boolean flag indicating whether to return a generic component instance.
23+
* If `true`, returns a `GenericComponentInstance` including vapor instance.
24+
* If `false` or unset, returns a `ComponentInternalInstance` if available.
25+
* @returns The current component instance, or `null` if no instance is active.
26+
*/
27+
export function getCurrentInstance(
28+
generic: true,
29+
): GenericComponentInstance | null
30+
export function getCurrentInstance(
31+
generic?: boolean,
32+
): ComponentInternalInstance | null
33+
export function getCurrentInstance(generic?: boolean) {
34+
return currentInstance && (generic || !currentInstance.vapor)
35+
? currentInstance
2236
: currentRenderingInstance
37+
}
2338

2439
export let isInSSRComponentSetup = false
2540

0 commit comments

Comments
 (0)